<?php

class DiaryController
{
    private $diaryAttachmentModel;
    private $diaryBodyModel;
    private $diaryListModel;
    private $commentModel;
    private $followModel;
    private $userStatisticsModel;
    private $lbsModel;
    private $autoUidModel;
    private $feedModel;
    private $diaryListCacheModel;
    private $shopModel;
    private $groupInfoModel;
    private $topicModel;
    private $topicCommentsModel;
    private $voteModel;
    private $groupMembersModel;
    private $userSettingModel;

    function __construct()
    {
        $this->diaryAttachmentModel =   new DiaryAttachmentModel();
        $this->diaryBodyModel       =   new DiaryBodyModel();
        $this->diaryListModel       =   new DiaryListModel();
        $this->commentModel         =   new CommentModel();
        $this->followModel          =   new FollowModel();
        $this->userStatisticsModel  =   new UserStatisticsModel();
        $this->lbsModel             =   new LbsModel();
        $this->autoUidModel         =   new AutoUidModel();
        $this->feedModel            =   new FeedModel();
        $this->diaryListCacheModel  =   new DiaryListCacheModel();
        $this->shopModel            =   new ShopModel();
        $this->groupInfoModel       =   new GroupInfoModel();
        $this->topicModel          	=   new TopicModel();
        $this->topicCommentsModel   =   new TopicCommentsModel();
        $this->groupMembersModel        =   new GroupMembersModel();
        $this->userSettingModel        =   new UserSettingModel();
        $this->voteModel            =   new VoteModel();
        $this->actions =   array(
            'getDiaryWithComments','createDiaryTopic','getDiaryTopicInfo','getDiaryTopicList','searchDiaryTopics','getDiarysByTopic','voteDiary',
            'addFollowTopic', 'removeFollowTopic', 'getFollowTopics', 'diaryAddTop', 'diaryRemoveTop', 'videoPlay','editDiary','subscriptionReward',
            'getRewardList','getHotDiaryTopicList'
        );
    }
    
    /**
     * 路由
     * @param unknown $param
     * @return unknown
     */
    public function callApi($param) {
        $ac = $param['action'];
        $doCheck    =   $this->checkAction($ac);
        if (!empty(AC::$errorNo)) {
            return  $doCheck;
        }
    
        return $this->$ac($param);
    }
    
    /**
     * 获取点滴详情
     * @param unknown $diaryInfo
     * @return boolean|multitype:unknown unknown Ambigous <boolean, Ambigous> Ambigous <StdClass, multitype:number >
     */
    public function getDiaryWithComments ($diaryInfo) {
        $host_uid   =   AC::HOST_UID;
        $uid        =   intval($diaryInfo['uid']);
        $bodyId     =   intval($diaryInfo['bodyId']);
        if ($bodyId < 1) {
            AC::$errorNo    =   'DCC001';
            return  FALSE;
        }

        $access =   $this->checkAccessPremission($host_uid);
        if (empty($access)) return  FALSE;
        
        // 获取list结构数据
        $listInfo   = $this->getDiaryDetailListInfo($host_uid, $bodyId);
        if (AC::$errorNo) {
            AC::$errorNo = 'DCC007';
            return  FALSE;
        }

        if ($diaryInfo['inReview']==1) {
            AC::$errorNo = 'DCC020';//点滴审核中...
            return  FALSE;
        }
        
        // 获取body结构数据
        $bodyInfo   = $this->getDiaryDetailBodyInfo($listInfo['uid'], $bodyId,$listInfo);
        if (AC::$errorNo) {
            AC::$errorNo = 'DCC004';
            return  FALSE;
        }

        $tops = $this->getDiaryTopBodyids($bodyInfo['uid']);
        if (AC::$errorNo)AC::$errorNo = null;
        $bodyInfo['is_diarytop'] = in_array($bodyId, $tops) ? 1 : 0;
        
        // 获取评论结构数据
        $commentInfo = $this->getDiaryComments($bodyId, $listInfo['uid'], $listInfo['time']);
        if (AC::$errorNo) {
            $commentInfo = (Object) array();
        }
        // 获取热门评论结构数据
        $commentHotInfo = $this->getDiaryHotComments($bodyId, $listInfo['uid'], $listInfo['time']);
        if (AC::$errorNo) {
            $commentHotInfo = (Object) array();
        }

        // 获取关注结构数据
        $followInfo = $this->getDiaryDetailFollowInfo($listInfo['uid'], $host_uid);
        if (AC::$errorNo) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        if(AC::$subscription_pic_number){
        	$listInfo['attachmentList'] = array_slice($listInfo['attachmentList'] ,AC::$subscription_pic_number);
		}
		if(AC::$subscription_voice_number){
			$listInfo['voiceList'] = array_slice($listInfo['voiceList'] ,AC::$subscription_voice_number);
		}
		if(AC::$subscription_video_number){
			$listInfo['videoList'] = array_slice($listInfo['videoList'] ,AC::$subscription_video_number);
		}
		//标题
		$bodyInfo['title']  =    $this->diaryListModel->getSubscriptionTitle($listInfo);
		if(empty($listInfo['abbreviation'])){
            $bodyInfo['content'] = '';
        }
		// 返回数据
        $result = array(
            'bodyInfo'      =>  $bodyInfo,
            'attachment'    =>  $listInfo['attachmentList'],
            'voiceList'     =>  $listInfo['voiceList'],
            'videoList'     =>  $listInfo['videoList'],
            'listInfo'      =>  $listInfo,
            'user'          =>  $this->getDiaryDetailAuthor($listInfo['uid']),
            'commentInfo'   =>  $commentInfo,
            'commentHotInfo'=>  $commentHotInfo,
            'followInfo'    =>  $followInfo
        );

        //视频兼容老版本
        if(!empty($listInfo['videoList'])){
            $result['bodyInfo']['content'] = $result['listInfo']['abbreviation'] = UK::tipsUpgrade($listInfo['videoList'], $result['bodyInfo']['content'], 'video');
            AC::$video_version==0 && $result['listInfo']['attachmentPath'] = '';
        }
        
        $this->countTimes(array('uid' => $listInfo['uid'], 'bodyId' => $bodyId, 'viewTimes' => 1));
        
        return $result;
    }
    
    /**
     * 获取点滴评论
     * @param unknown $bodyId
     * @param unknown $uid
     * @return StdClass|Ambigous <StdClass, multitype:number >
     */
    private function getDiaryComments ($bodyId, $uid, $time) {
        if (empty($bodyId) || empty($uid)) return (Object) array();
        //新版本点滴评论取最新
        $product_version=    AC::$appInfoList[1];
        $os             =    strtolower(AC::$appInfoList[2]);
        $version = array(
            'android'          =>  '5.50',
            'ios'              =>  '5.5.0',
        );
        $sort = '';
        if($check = version_compare($product_version, $version[$os],  '>')){
            $sort = 'new';
        }
        if ($time >= AC::$diaryCommentCf['transfer_time']) {
            $comments = $this->topicCommentsModel->getDrabComments($bodyId, $uid, array(0, 0, 10), $sort);
        }else{
            $comments = $this->commentModel->getDiaryCommentList($uid, $bodyId, 0, 0, 10);
        }

        $result   = $this->commentModel->getCommentsOfDrabs($comments, $time);
        return $result;
    }

    /**
     * 获取点滴热门评论
     * @param unknown $bodyId
     * @param unknown $uid
     * @return StdClass|Ambigous <StdClass, multitype:number >
     */
    private function getDiaryHotComments ($bodyId, $uid, $time) {
        if (empty($bodyId) || empty($uid)) return (Object) array();
        $result = $this->diaryListCacheModel->getHotComment($bodyId);
        if($result){
            $comments = [];
            foreach ($result as $key => $val) {
                if ($time >= AC::$diaryCommentCf['transfer_time']) {
                    $commentInfo = $this->topicCommentsModel->getCommentInfo($val, $bodyId, $uid);
                    if(empty($commentInfo)) continue;
                    if($commentInfo['status'] != 0) continue;
                    $comments[] = $commentInfo; 
                }else{
                    $commentInfo = $this->commentModel->getOneComment(['uid'=>$uid, 'id'=>$val]);
                    if(empty($commentInfo)) continue;
                    $comments[] = $commentInfo; 
                }
            }
        }else{
            if ($time >= AC::$diaryCommentCf['transfer_time']) {
                $comments = $this->topicCommentsModel->getDrabComments($bodyId, $uid, array(0, null, null));
            }else{
                $comments = $this->commentModel->getDiaryCommentList($uid, $bodyId, 0, null, null);
            }
        }

        $result   = $this->commentModel->getCommentsOfDrabs($comments, $time, 1);
        $result = (array)$result;
        $result['comments'] = array_slice($result['comments'], 0, 10);
        if(empty($result['comments'])) {
            return (object)array();
        }
        $result['counts'] = count($result['comments']);
        return $result;
    }
    
    /**
     * 创建点滴话题
     * @param unknown $param
     * @return boolean|multitype:|Ambigous <boolean, unknown>
     */
    public function createDiaryTopic($param){
        $host_uid = AC::HOST_UID;
        $content  = UK::getstr($param['content'], AC::$diaryTopicCf['name_limit'], '', 1);
        $content  = preg_replace("/[^\x{4e00}-\x{9fa5}A-Za-z0-9\s]/iu",'',$content);
        
        $pattern = "/[A-Za-z0-9\x4e00-\x9fa5\s]+$/";
        if (strlen($content) < 1 && !preg_match_all($pattern,$content,$mat)) {
            AC::$errorNo    = 'DTC003';
            AC::$errorMsg   = '抱歉，目前只支持中文、字母、数字组合';
            return  FALSE;
        }
        
        if (empty($host_uid) || strlen($content) < 1) {
            AC::$errorNo    =   'DTC001';
            return  FALSE;
        }
        
        $diaryTopic = $this->groupInfoModel->getDiaryTopicInfoByName($content); 
        if (empty($diaryTopic)){
            $gid = $this->groupInfoModel->createDiaryTopic($host_uid, $content);
            if(empty($gid)) return (Object) array();
            
            $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($gid);
        }
        
        $this->checkDiaryTopicIsValid($diaryTopic);
        if (AC::$errorNo) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return FALSE;
        }
    	
    	$result = $this->groupInfoModel->assembleDataOfDiaryTopic($diaryTopic);
    			
    	$this->syncDiaryTopicToCache($diaryTopic);
        return $result;
    }
    
    /**
     * 点滴话题详情
     * @param unknown $param
     * @return boolean|Ambigous <boolean, multitype:unknown Ambigous <> >
     */
    public function getDiaryTopicInfo($param) {
        $host_uid = AC::HOST_UID;
        $uid      = intval($param['uid']);
        $topic_id = intval($param['topic_id']);

        if (empty($topic_id)){
            AC::$errorNo    =   'DTC001';
            return false;
        }

        $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($topic_id);
        $this->checkDiaryTopicIsValid($diaryTopic);
        if (AC::$errorNo) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return FALSE;
        }

        $result = $this->groupInfoModel->assembleDataOfDiaryTopic($diaryTopic);
        $this->groupInfoModel->addDiaryTopicViewOrDiscussNum($topic_id);

        $data = array('topic_id' => $topic_id,'length' => 10);
        if($result['type'] == AC::$diaryTopicCf['official']) {
            $data['sort'] = 'hot';
        }
        $diarys = $this->getDiarysByTopic($data);
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        $result['me_follow'] = in_array( $topic_id, $gids );
        $result['diarys'] = array(
            'list'    =>  $diarys,
            'counts'  =>  count($diarys)
        );
        
        return $result;
    }
    
    /**
     * 点滴话题列表
     * @param unknown $param
     * @return Ambigous <boolean, StdClass>
     */
    public function getDiaryTopicList($param) {
        $host_uid = AC::HOST_UID;
        $uid      = intval($param['uid']);
        $type     = strval($param['type']);
    
        if (empty($host_uid) || empty($type)){
            AC::$errorNo    =   'DTC001';
            return false;
        }
        
        // 请求数据库
        $type        = isset(AC::$diaryTopicCf[$type]) ? AC::$diaryTopicCf[$type] : 1;
        list($id, $start, $length) = UK::assemblePageData($param);
        $diaryTopics = $this->groupInfoModel->getDiaryTopics($type, $id, $start, $length);
        if(empty($diaryTopics)) return (Object) array();
        
        // 返回数据
        $topics = $this->groupInfoModel->loopGroupList($diaryTopics);
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        $this->topicsCheckMeFollow($topics, $gids);
        $result = array('topics' => $topics, 'count' => count($topics));
        return $result;
    }

    /**
     * 热门话题列表
     * @param  $param
     * @return  <boolean, StdClass>
     */
    public function getHotDiaryTopicList($param) {
        $host_uid = AC::HOST_UID;
        $uid      = intval($param['uid']);
        $type     = strval($param['type']);
        $id       = isset($param['id']) ? intval($param['id']) : 0;
        if (empty($host_uid) || empty($type)){
            AC::$errorNo    =   'DTC001';
            return false;
        }

        // 请求缓存
        $start       = 0;
        $length      = 20;
        if($id) {
            $gidRank   = $this->diaryListCacheModel->getDiaryTopicRank($id);
            $start     = $gidRank + 1;
        }
        $start < 0 && $start = 0;
        $diaryTopics = $this->diaryListCacheModel->getDiaryTopicCache($start, $length);

        if(empty($diaryTopics)) return (Object) array();

        // 返回数据
        $topics = $this->groupInfoModel->loopGroupListByGid($diaryTopics);
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        $this->topicsCheckMeFollow($topics, $gids);
        $result = array('topics' => $topics, 'count' => count($topics));
        return $result;
    }


    /**
     * 搜索点滴话题列表
     * @param unknown $uid
     * @param unknown $keyword
     * @param unknown $length
     * @param unknown $start
     */
    public function searchDiaryTopics($param) {
        $host_uid = AC::HOST_UID;
        $uid      = intval($param['uid']);
        $key_word = UK::getstr($param['keyword'], 36, '', 1);
    
        if(empty($host_uid) || strlen($key_word) < 1){
            AC::$errorNo    =   'DTC001';
            return  FALSE;
        }
        
        $list   = $this->groupInfoModel->getSearchDiaryTopics($key_word);
        if (empty($list)) return (Object) array();
    
        $list   = $this->groupInfoModel->loopGroupList($list);
        $result = array('topics' => $list, 'count' => count($list));
        return $result;
    }
    
    /**
     * 同步到redis
     * @param unknown $info
     */
    private function syncDiaryTopicToCache ($info) {
        $data = array(
            'id'    =>  intval($info['gid']),
            'title' =>  strval($info['name']),
            'ext'   =>  $info,
            'time'  =>  AC::SERVER_TIME
        );
        
        $message = UK::JsonFormat($data);
        RedisPool::addDiaryTopicCreateJob('diarytopic_create', $message);
    }
    
    /**
     * 根据话题搜索点滴
     * @param unknown $param
     * @return boolean|StdClass
     */
    public function getDiarysByTopic ($param) {
        $host_uid = AC::HOST_UID;
        $uid      = intval($param['uid']);
        $topic_id = intval($param['topic_id']);
        
        if(empty($topic_id)){
            AC::$errorNo    =   'DTC001';
            return  FALSE;
        }
        
        $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($topic_id);
        $this->checkDiaryTopicIsValid($diaryTopic);
        if (AC::$errorNo) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return FALSE;
        }
        
        list($id, $start, $length) = UK::assemblePageData($param);
        if(isset($param['sort']) && $param['sort'] == 'hot'){
            $start = 0;
            if($id > 0){
                $start = $this->diaryListCacheModel->getTopicHotDiaryRank($topic_id, $id);
                $count = $this->diaryListCacheModel->getTopicHotDiaryCount($topic_id);
                //倒序
                $start = $count - $start;
            }
            $result = $this->getTopicHotDiary($topic_id, $start, $length);
            return $result;
        }
        $topics = $this->topicModel->getTopicDiarys($topic_id, $id, $start, $length);
        if (empty($topics)) return array();
        
        $result = $this->getDiarys($topics);
        return $result;
    }
    
    /**
     * 获取点滴列表
     * @param unknown $topics
     * @return multitype:Ambigous <multitype:, multitype:, multitype:string >
     */
    private function getDiarys($topics){
        $result = array();
        foreach ($topics    as  $list){
            $tmp          =   $this->diaryListModel->getDiaryInfoByBodyId($list['type_id']);
			if(empty($tmp) || intval($tmp['secret'])>0 || intval($tmp['status'])>0){
                continue;
            }
    
            $tmp['id']    =   $tmp['bodyId'];
            $list         =   $this->feedModel->square($tmp);
            $result[]     =   $list;
        }
        return $result;
    }

    private function getTopicHotDiary($topic_id, $start, $length) {
        if(empty($topic_id)) return false;
        $diaryList = $this->diaryListCacheModel->getTopicHotDiary($topic_id, $start, $length);

        if(empty($diaryList)){
            $recommendModel = new RecommendModel();
            $diaryInfoList = $recommendModel->getTopicHotDiary($topic_id);
            if($diaryInfoList) return array();
            $diaryService = new DiaryService();
            foreach ($diaryInfoList as $value) {
                $diaryService->addHotDiary($value['type_id'], $value['create_at']);
            }
            $diaryList = $this->diaryListCacheModel->getTopicHotDiary($topic_id, $start, $length);
        }
        $result = array();
        foreach ($diaryList as $value) {
            $diaryInfo = $this->diaryListModel->getDiaryInfoByBodyId($value);
            if(empty($diaryInfo) || intval($diaryInfo['secret'])>0 || intval($diaryInfo['status'])>0){
                continue;
            }

            $tmp['id']    =   $diaryInfo['bodyId'];
            $list         =   $this->feedModel->square($diaryInfo);
            $result[]     =   $list;
        }
        return $result;
    }
    
    public function getDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DC002';
            return  FALSE;
        }
        if (!empty($diaryInfo['secret']))
        {
            if (AC::HOST_UID    !=  $diaryInfo['uid'])
            {
                AC::$errorNo    =   'DC009';
                return  FALSE;
            }
        }

        #   access = FALSE  don't have premission to access this!
        $access =   $this->checkAccessPremission($diaryInfo['uid']);
        if (empty($access)) return  FALSE;

        if (empty($diaryInfo['listMode']))
        {
            $list   =   $this->diaryListModel->getDiaryList($diaryInfo);
        }
        else
        {
            if ('up' == $diaryInfo['listMode'])
            {
                $list   =   $this->diaryListModel->getDiaryListUp($diaryInfo);
            }
            else
            {
                $list   =   $this->diaryListModel->getDiaryListDown($diaryInfo);
            }
        }
        if (!empty($list)   &&  is_array($list))
        {
            foreach ($list  as  &$record)
            {
                $record['retweeted_status']  = $this->diaryListModel->manipulationListData($record);
                if (empty($record['attachmentPath']) || empty($record['uid'])   ||  empty($record['bodyId']))   continue;
                // 增加了语音附件
                $attachment   =   $this->diaryAttachmentModel->getDiaryAllAttachment($record);
                $record['attachmentList']    =    $attachment['attachmentList'];
                $record['voiceList']         =    $attachment['voiceList'];
            }
        }
        return  $list;
    }/*}}}*/
    
    /**
     * 用户公开或私密日记列表
     * @param unknown $diaryInfo
     * @return boolean|Ambigous <boolean, unknown, multitype:>
     */
    public function getUserDiaryList($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']))
        {
            AC::$errorNo    =   'DC002';
            return  FALSE;
        }
        if (!empty($diaryInfo['secret']))
        {
            if (AC::HOST_UID    !=  $diaryInfo['uid'])
            {
                $diaryInfo['secret'] = '';
            }
        }
        #   access = FALSE  don't have premission to access this!
        $access =   $this->checkAccessPremission($diaryInfo['uid']);
        if (empty($access)) return  FALSE;

        $list   =   $this->diaryListModel->getDiarySecretList($diaryInfo);
       
        if (!empty($list)   &&  is_array($list))
        {
            $this->appendTopDiaryToList($list, $diaryInfo);
            foreach ($list  as  &$record) {
                if (empty($record)) {
                    continue;
                }
                $userInfo = $this->autoUidModel->getUserInfo($record['uid']);
                $record['nickname'] = $userInfo['nickname'];
                $record['is_favor'] = $this->diaryListModel->checkIsLike(AC::HOST_UID, $record['bodyId']);
                $record['geo']      = $this->diaryListModel->filterGeoData($record['geo']);
                $record['is_diarytop'] = $record['is_diarytop'] ? $record['is_diarytop'] : 0;
                $record = $this->feedModel->square($record);
            }
        }
        return  $list;
    }/*}}}*/

    /**
     * 将会员置顶的点滴加入list
     * @param $list
     * @param $uid
     */
    private function appendTopDiaryToList(&$list, $diaryInfo){
        if ($diaryInfo['secret']){
            return ;
        }
        $uid = $diaryInfo['uid'];
        $toplist = $this->getDiaryTopBodyids($uid);
        if (empty($toplist)) return ;
        $top_bodyid = $toplist[0];
        $top_body = $this->diaryListModel->getDiaryListInfoByBodyId($top_bodyid);
        if (empty($top_body) || $top_body['status'] || $top_body['secret']){//点滴不存在或转为私密，删除置顶标识
            $set = [ 'diary_top'=>'' ];
            $this->userSettingModel->saveSetting($uid, $set);
            return ;
        }
        $top_body['is_diarytop'] = 1;
        $tmp = [];
        foreach ($list as $item){
            if ($item['bodyId']==$top_bodyid)continue;//将与置顶重复的点滴剔除
            $tmp[] = $item;
        }
        $list = $tmp;
        empty($diaryInfo['id']) && array_unshift($list, $top_body);
    }
    
    public function getDiaryInfo($diaryInfo)/*{{{*/
    {
        $diaryBody  =   $this->getDiaryInfoDetail($diaryInfo);
        if (empty($diaryBody['bodyInfo']))  return  $diaryBody;

        $diaryInfo['type']          =   AC::FEED_DIARY;
        $diaryBody['commentInfo']   =   $this->commentModel->getCommentInfo($diaryInfo);
        return  $diaryBody;
    }/*}}}*/
    /**
     * 老版日记详情接口
     * @param unknown $diaryInfo
     * @return Ambigous <boolean, multitype:Ambigous <> Ambigous <Ambigous, boolean, number, string> Ambigous <Ambigous, NULL, multitype:multitype: string NULL unknown Ambigous <string, unknown> Ambigous <> , boolean, string> Ambigous <boolean, multitype:, unknown> Ambigous <multitype:> >|Ambigous <StdClass, string, boolean, unknown, multitype:>
     */
    public function getDiaryInfoWithCommentReply($diaryInfo)/*{{{*/
    {
        $diaryBody  =   $this->getDiaryInfoDetail($diaryInfo);
        if (empty($diaryBody['bodyInfo']))  return  $diaryBody;    

        $diaryInfo['type']          =   AC::FEED_DIARY;
        $diaryBody['commentInfo']   =   $this->commentModel->getCommentTop($diaryInfo);
        // 处理评论以及评论附件
        $this->diaryDetailInfo($diaryBody);
 
       
        #判断是否转发
        if(intval($diaryBody['listInfo']['rBodyId']) > 0  && intval($diaryBody['listInfo']['rUid']) > 0){
            $repost['rBodyId']    =    $diaryBody['listInfo']['rBodyId'];
            $repost['rUid']       =    $diaryBody['listInfo']['rUid'];
            
            $diaryBody['retweeted_status']  = $this->rebuildRetweeted($repost);
        }
        // 判断是否老版本
        if (intval($diaryBody['listInfo']['rUid']) > 0 && intval($diaryBody['listInfo']['rBodyId']) > 0 && AC::$userVersion == '1'){
            $diaryBody['bodyInfo']['content']        = $this->feedModel->iosRepostConnentByDetail($diaryBody);
            $diaryBody['listInfo']['abbreviation']   = $this->feedModel->iosRepostConnentByDetail($diaryBody);
            $diaryBody['listInfo']['attachmentPath'] = $diaryBody['retweeted_status']['listInfo']['attachmentPath'];
            $diaryBody['attachment']                 = $diaryBody['retweeted_status']['attachment'];
        }
        // 过滤表情#号
        $diaryBody['listInfo']['abbreviation']   =    Emotion::emotionToCharacter($diaryBody['listInfo']['abbreviation']);
        // 判断跟用户关系
        if (AC::HOST_UID    !== $diaryInfo['uid'])
        {
            $diaryBody['followInfo']   =   $this->followModel->getFollowInfo(array('uid' => AC::HOST_UID, 'fUid' => $diaryInfo['uid']));
        }
       
        
        $geo    =   $diaryBody['listInfo']['geo'];
        $diaryBody['listInfo']['geo']=(Object)array();
        if(!empty(UK::getstr($geo['name'], 50, '', 1)) && !empty($geo['citycode']))
        {
            $diaryBody['listInfo']['geo']=$geo;
        }
                    
        return  $diaryBody;
    }/*}}}*/
    
    /**
     * 日记详情改版
     * @param unknown $diaryInfo
     * @return boolean|multitype:unknown Ambigous <boolean, Ambigous> Ambigous multitype:StdClass  unknown
     */
    public function getDiaryDetailByGuest ($diaryInfo) {
        $host_uid   =   AC::HOST_UID;
        $uid        =   intval($diaryInfo['uid']);
        $bodyId     =   intval($diaryInfo['bodyId']);
        if ($bodyId < 1) {
            AC::$errorNo    =   'DC003';
            return  FALSE;
        }

        $access =   $this->checkAccessPremission($host_uid);
        if (empty($access)) return  FALSE;

        // 获取list结构数据
        $listInfo   = $this->getDiaryDetailListInfo($uid, $bodyId);
        if (!empty(AC::$errorNo)) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // uid赋值
        $uid = $listInfo['uid'];
        
        // 获取body结构数据
        $bodyInfo   = $this->getDiaryDetailBodyInfo($uid, $bodyId);
        
        // 获取评论结构数据
        $commentInfo= $this->getDiaryDetailCommentInfo($uid, $bodyId);
        if (!empty(AC::$errorNo)) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 获取作者结构数据
        $author     = $this->getDiaryDetailAuthor($uid);
        
        // 获取关注结构数据
        $followInfo = $this->getDiaryDetailFollowInfo($uid, $host_uid);
        if (!empty(AC::$errorNo)) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 返回数据
        $result = array(
            'listInfo'      =>  $listInfo,
            'bodyInfo'      =>  $bodyInfo,
            'attachment'    =>  $listInfo['attachmentList'],
            'voiceList'     =>  $listInfo['voiceList'],
            'commentInfo'   =>  $commentInfo,
            'followInfo'    =>  $followInfo,
            'user'          =>  $author
        );
        
        return $result;
    }
  
    /**
     * 新的日志详情接口  
     * @param unknown $diaryInfo
     * @return Ambigous <boolean, multitype:multitype:NULL string  Ambigous <boolean, multitype:> Ambigous <boolean, multitype:, unknown> Ambigous <multitype:, boolean, unknown> >|Ambigous <string, boolean, unknown, multitype:, NULL, multitype:unknown Ambigous <string, unknown> >
     */
    public function getDiaryDetail($diaryInfo){
        $diaryBody  =   $this->getDiaryRebuildDetail($diaryInfo);
        if (empty($diaryBody['bodyInfo']))  return  $diaryBody;
        $detail           =    $this->diaryListModel->rebuildDiaryDetail($diaryBody);
        $diaryInfo['type']          =   AC::FEED_DIARY;
        $detail['commentInfo']      =   $this->commentModel->getCommentTop($diaryInfo);
        $this->diaryDetailInfo($detail);
        #判断是否转发
        if((intval($detail['rBodyId']) > 0)  && (intval($detail['rUid']) > 0) ){
            $repost['bodyId']    =    $detail['rBodyId'];
            $repost['uid']       =    $detail['rUid'];
            
            $retweeted_status              =    $this->getDiaryRebuildDetail($repost);
            $detail['retweeted_status']    =    $this->diaryListModel->rebuildDiaryDetail($retweeted_status);
            
        }
        // 判断是否老版本
        if (intval($detail['rUid']) > 0 && intval($detail['rBodyId']) > 0 && AC::$userVersion == '1'){
            $detail['content']        = $this->feedModel->iosRepostConnentByNewDetail($detail);     
            $detail['attachmentList'] = $detail['retweeted_status']['attachmentList'];
        }
        
        // 表情对应的列表
        $emotion_ids_mebuy = array();
        if ($diaryBody['bodyInfo']['extend']){
            $extend_arr = json_decode($diaryBody['bodyInfo']['extend'], TRUE);
            $emotion_ids_mebuy = $extend_arr['shop_ids_mebuy'];
        }
        if (empty($emotion_ids_mebuy) && $diaryBody['bodyInfo']['saveTime'] < Emotion::$filter_emotion_update_time){
            $emotion_ids_mebuy = Emotion::$default_emotion_ids;
        }
        
        $detail['imageList'] = Emotion::emotionToImgList($detail['content'], $emotion_ids_mebuy);
        $detail['content']   = Emotion::emotionToMark($detail['content'], $emotion_ids_mebuy);
        
        return $detail;
    }
    /**
     * 处理评论信息,以及评论附件
     * TODO 如果评论的主题内容使用分表,则需要在这查询一次分表,将评论的内容取出
     * @param unknown $detail
     */
    private function diaryDetailInfo(&$detail){
        if (empty($detail['commentInfo'])){
            return (Object) array();
        }
        foreach ($detail['commentInfo'] as &$comment){
            $userInfo = $this->autoUidModel->getUserInfo($comment['cUid']);
            $comment['avatar']  =  $userInfo['avatar'];
            $comment['user']    =  $this->autoUidModel->checkIsMe($userInfo);
            if ($comment['replyList'] && count($comment) > 0)
            {
            	foreach ($comment['replyList'] as &$reply)
            	{
            		$replyCuser = $this->autoUidModel->getUserInfo($reply['cUid']);
            		$replyRuser = $this->autoUidModel->getUserInfo($reply['rUid']);
            		$reply['cNickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$reply['cUid'],'nickname'=>$replyCuser['nickname']));
            		$reply['rNickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$reply['rUid'],'nickname'=>$replyRuser['nickname']));
            	}
            }
            $comment['user']['nickname']  =    $this->autoUidModel->getRemarkName($comment['user']);
            $comment['cNickname'] = $comment['user']['nickname'];
        }
    }
    
    private function getDiaryRebuildDetail($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DC003';
            return  FALSE;
        }
    
        #   access = FALSE  don't have premission to access this!
        $access =   $this->checkAccessPremission($diaryInfo['uid']);
        if (empty($access)) return  FALSE;

        $listInfo   =   $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);
        if (empty($listInfo))
        {
            AC::$errorNo    =   'DC004';
            return  FALSE;
        }
        if (1   ==  $listInfo['secret'])
        {
            if (AC::HOST_UID    !=  $diaryInfo['uid'])
            {
                AC::$errorNo    =   'DC008';
                return  FALSE;
            }
        }
        $attachmentList =   array();
        if (!empty($listInfo['attachmentPath']))
        {
            $attachmentList =   $this->diaryAttachmentModel->getDiaryAllAttachment($diaryInfo);
        }

        $bodyInfo   =   $this->diaryBodyModel->getDiaryBody($diaryInfo['uid'], $diaryInfo['bodyId']);
        if (!empty(AC::$errorNo))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 返回信纸地址
        if (isset($bodyInfo['paper_url'])){
            $bodyInfo['paper_url'] = $this->generatePaperUrl($bodyInfo['paper_url']);
        }

        $data['uid']        =   $diaryInfo['uid'];
        $data['bodyId']     =   $diaryInfo['bodyId'];
        $data['viewTimes']  =   1;
        $result =   $this->countTimes($data);
        // 尚未启用,暂时关闭
        $geo = array();
//         $geo                        =   $this->lbsModel->getDiaryListGeo($diaryInfo);
       if (empty($geo)) {
           $geo    =  (Object) array();
       }
       
       // 转发的分享结构
       $structData = array();
       if($listInfo['extras']){
           $structData = $this->diaryListModel->structData($listInfo);
           if (!empty($structData)) {
               $listInfo['viewTimes']      =    strval($structData['viewTimes']);
               unset($structData['viewTimes']);
           }
       }
       $listInfo['url_struct']    =    array();
       if (!empty($structData)){
           $listInfo['url_struct'][] = $structData;
       }
       unset($listInfo['extras']);
        
        $user = $this->autoUidModel->getUserInfo($diaryInfo['uid'],'',AC::HOST_UID);
        $user['nickname']  =    $this->autoUidModel->getRemarkName($user);

        // 限制附件显示数量
        $attachmentList['attachmentList'] = array_slice($attachmentList['attachmentList'], 0, AC::$topicDiaryAttachmentLimit );
        // 增加了语音附件
        return  array('bodyInfo' => $bodyInfo, 'attachment' => $attachmentList['attachmentList'], 'voiceList' => $attachmentList['voiceList'], 'listInfo' => $listInfo,'user'=> $user,'geo' => $geo);
    }/*}}}*/
    
    private function generatePaperUrl($url){
        // $url = "10001_summer_04_caymZzRH"
        $result = "";
        $base   =  AC::getProtocolUriByOS(AC::$cdn_url_d);
        $base   .=  "/diary/paper/";
        $format = '.jpg';
        
        if (empty($url)) {
            return $result;
        }
        
        $result = preg_replace('/_/', "/", $url, 2);
        if (empty($result)){
            return $result;
        }
        $result = $base.$result.$format;
        return  $result;
    }

    private function generateVipCardUrl($url){
        if (empty($url))return '';
        $result   =  AC::getProtocolUriByOS(AC::$cdn_url_d).$url;
        return  $result;
    }
    
     public function rebuildRetweeted($Info){
    
        $repost['bodyId'] = intval($Info['rBodyId']);
        $repost['uid']    = intval($Info['rUid']);
        
        //被拉黑了就直接返回错误
        $access =   $this->checkAccessPremission($repost['uid']);
        if (!$access){
            AC::$errorNo    =   '';
            return (Object) array();
        }
        $listInfo   =   $this->diaryListModel->getDiaryInfoByBodyId($repost['bodyId']);
        if (empty($listInfo) || $listInfo['secret'] == 1){
            return (Object) array();
        }
        $attachment =   array();
        if (!empty($listInfo['attachmentPath']))
        {
            $attachment =   $this->diaryAttachmentModel->getDiaryAllAttachment($repost);
        }
        
        $bodyInfo   =   $this->diaryBodyModel->getDiaryBody($repost['uid'], $repost['bodyId']);
        if (empty($bodyInfo))
        {
           return (Object) array();
        }
        
        $diaryInfo['listInfo']         =    $listInfo;
        $diaryInfo['bodyInfo']         =    $bodyInfo;
        // 增加了语音附件
        $diaryInfo['attachment']       =    $attachment['attachmentList'];
        $diaryInfo['voiceList']        =    $attachment['voiceList'];
        
        $data['uid']        =   $repost['uid'];
        $data['bodyId']     =   $repost['bodyId'];
        $data['viewTimes']  =   1;
        $result             =   $this->countTimes($data);
        // 尚未启用,暂时关闭
        $geo = array();
        //$geo       =   $this->lbsModel->getDiaryListGeo($repost);
        if (empty($geo)){
            $geo = (Object) array();
        }
        $diaryInfo['geo']    =    $geo;
        $diaryInfo['bodyInfo']['nickname']    =    '';
        $diaryInfo['listInfo']['nickname']     =    '';
        $userInfo  = $this->autoUidModel->getUserInfo($repost['uid'],'',AC::HOST_UID);
        if (!empty($userInfo)){
            // 获取备注名
            $diaryInfo['bodyInfo']['nickname']  = $this->autoUidModel->getRemarkName($userInfo);
            $diaryInfo['listInfo']['nickname']  = $this->autoUidModel->getRemarkName($userInfo);
        }
        return $diaryInfo;
    }

    public function addDiary($diaryInfo)
    {
        // 检查是否被禁言
        $status  =  $this->autoUidModel->checkUserStatus(AC::$hostUserBaseInfo);
        if (!empty(AC::$errorNo)){
            return  FALSE;
        }
        if (AC::HOST_UID != $diaryInfo['uid']){
            AC::$errorNo    =   'UC010';
            return  FALSE;
        }
        
        $diaryInfo['topics'] = $this->assembleDiaryTopics($diaryInfo['topic_id']);
        if (AC::$errorNo) return false;
        
        // 分享
        if (!empty($diaryInfo['data_action'])) {
            $shareData = $this->restructShareData($diaryInfo, $diaryInfo['uid']);
            $diaryInfo['extras'] = $shareData['extras'];
            $extras = json_decode($diaryInfo['extras'], true);
            if(!empty($extras) && isset($extras['article']) && empty($diaryInfo['content'])) {
                $diaryInfo['content'] = '分享文章';
            }
        }
        
        $max_numbers = AC::$hostUserBaseInfo['max_numbers'] * 3;
        // 字符串截取
        $diaryInfo['content'] = UK::getstr($diaryInfo['content'], $max_numbers);
        $diaryInfo['title']   = UK::getstr($diaryInfo['title'], 120, '', 1);
        
        #判断是否是转发
        if (intval($diaryInfo['zfBodyId']) > 0 && intval($diaryInfo['zfUid']) > 0){
            $access =   $this->checkAccessPremission($diaryInfo['zfUid']);
            if (!$access) return FALSE;
            //检测是否被点滴作者屏蔽
            $permissionService = new PermissionService();
            $shieldCheck = $permissionService->checkShieldUser($diaryInfo['zfUid']);
            if (empty($shieldCheck)) return false;
            //提前释放检测类，以免被其析构函数影响到后续报错信息
            $permissionService = NULL;
            $diaryInfo    =     $this->diaryListModel->repeatDataHandle($diaryInfo);
            if (!$diaryInfo){
                return false;
            }
        }
        if (strlen($diaryInfo['content']) < 1){
            AC::$errorNo    =   'DC001';
            return  FALSE;
        }
        
        // 判别是否重复提交
        if (empty($diaryInfo['data_action'])) {
            $ck = $this->diaryListModel->checkLastContent($diaryInfo);
            if (AC::$errorNo){
                UK::varDump(AC::$errorNo, __METHOD__);
                return  FALSE;
            }
        }
        
        // 更新用户活跃时间
        $this->autoUidModel->updateUserLastActivity($diaryInfo['uid']);

        //带有视频的点滴，标记类型type=1
        unset($diaryInfo['diaryType']);
        if (isset($diaryInfo['video']) && isset($diaryInfo['video'][0]) && is_array($diaryInfo['video'][0])){
            $diaryInfo['diaryType'] = 1;
            //检查用户发视频权限
            $user = $this->checkUserPostVideoAccess($diaryInfo['uid']);
            if (AC::$errorNo){
                return false;
            }
        }else{
            //检查非视频话题的topic_id
            if ($diaryInfo['topic_id'] && $diaryInfo['topic_id']==107029){
                AC::$errorNo = 'UC042';
                AC::$errorMsg = '只有带有短视频的点滴才能发到此话题哦';
                return false;
            }
            //检查非视频点滴的label值
            if ($diaryInfo['label'] == 12) {
                $diaryInfo['label'] = 0;
            }
        }
        //点滴投票
	$vote = $this->voteModel->filterTopicVote($diaryInfo['vote']);
	if (AC::$errorNo) {
	return  false;
	}
	$diaryInfo['vote'] = $vote ? 1 : 0;
	
        // 获取信纸id
        $pid = $this->assembleDiaryPaperId($diaryInfo['paper']);
        $diaryInfo['extend'] = $this->assembleDiaryExtend($diaryInfo['uid'], $pid, $diaryInfo['content'], $diaryInfo['paper'], $diaryInfo);
        //diaryList extras结构处理
        $this->assembleDiaryListExtrasFromExtend($diaryInfo['extras'], $diaryInfo['extend']);

        $diaryId    =   $this->diaryBodyModel->addDiaryBody($diaryInfo);
        if (empty($diaryId))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        $this->diaryListCacheModel->setLastCheckConnent($diaryInfo['uid'], $ck);

        $diaryInfo['bodyId']=   $this->diaryBodyModel->getBodyId($diaryInfo['uid'], $diaryId);
        if (empty($diaryInfo['bodyId']))

        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }

        //发视频到审核列表
        if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1){
            $diaryVideoModel = new DiaryVideoModel();
            $diaryVideo = $diaryInfo;
            $diaryVideoModel->addDiaryVideo($diaryVideo);
            unset($diaryVideo);
        }

        // 写附件信息
        $this->addDiaryAttachment($diaryInfo);
     
        // 组装geo信息
        $diaryInfo['geo'] = $this->assembleDiaryGeo($diaryInfo['geo']);
        
        $diaryListInsert=   $this->diaryListModel->addDiaryList($diaryInfo);
        if (empty($diaryListInsert))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }

		// 投票
		$voteInfo = array('uid' => AC::HOST_UID, 'tid' => $diaryInfo['bodyId'], 'vote' => $vote);
		if($vote){
			$voteLinkId = $this->voteModel->addVoteLink($diaryInfo['uid'], $diaryInfo['bodyId'], $vote);
			if ($voteLinkId) {
				$voteOptionsId = $this->voteModel->addVoteOptions($diaryInfo['uid'], $diaryInfo['bodyId'], $vote, $voteLinkId);
			}
		}

		if (AC::$errorNo) {
			UK::varDump(AC::$errorNo, __METHOD__);
			return  FALSE;
		}

        $result =   array('bodyId' => $diaryInfo['bodyId']);
        //将日志加入redis缓存
        $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);
        
        if (!empty($diaryInfo['secret']))
        {
            AC::$userStatistics[$diaryInfo['uid']]['secretDiaryTimes']  =   1;
            if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1){
                $this->sendReviewQueue($diaryInfo, $user);//私密点滴也进审核
            }
            return  $result;
        }
        AC::$userExpAction['action'] = "diaryTimes";
        #判断是否是转发
        if (intval($diaryInfo['zfBodyId']) > 0  && intval($diaryInfo['zfUid']) > 0){
            $this->diaryListModel->repeatStatitcs($diaryInfo);
            AC::$userExpAction['action'] = "repostTimes";
        }
        //发视频审核不进时间线
        if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1){
            //不进时间线
        }else{
            $this->diaryListCacheModel->addUserTimeline($diaryInfo['uid'], $diaryInfo['bodyId']);
        }
        #  feed & statistics    /*{{{*/
        AC::$userStatistics[$diaryInfo['uid']]['diaryTimes']    =   1;
        
        AC::$feedInfo   =   array(
                                'uid'               =>  $diaryInfo['uid'],
                                'eUid'              =>  AC::$hostUserBaseInfo['uid'],
                                'eNickname'         =>  AC::$hostUserBaseInfo['nickname'],
                                'authorUid'         =>  AC::$hostUserBaseInfo['uid'],
                                'authorNickname'    =>  AC::$hostUserBaseInfo['nickname'],
                                'bodyId'            =>  $diaryInfo['bodyId'],
                                'type'              =>  AC::FEED_DIARY,
                                'label'          =>   (isset($diaryInfo['label']) && intval($diaryInfo['label']) > 0 && intval($diaryInfo['label']) <= AC::DIARY_TAG_MAXID) ? intval($diaryInfo['label']) : 0
                            );
        strlen($diaryInfo['content']) > 0    &&  AC::$feedInfo['content']    =   $diaryInfo['content'];
        strlen($diaryInfo['title']) > 0      &&  AC::$feedInfo['content']    =   $diaryInfo['title'];
        strlen(AC::$feedInfo['content']) < 1 &&  AC::$feedInfo['content']    =   ' write Diary, No title ? No content ? ! ';
        
        #判断是否是转发
        if (intval($diaryInfo['zfBodyId']) > 0  && intval($diaryInfo['zfUid']) > 0){
            $this->feedModel->setRepostInfo(AC::$feedInfo, $diaryInfo);
            AC::$feedInfo['type'] = AC::FEED_REPOST;
            
            // 转发并评论
            if (isset($diaryInfo['comment']) && !empty($diaryInfo['comment']) && empty(AC::$errorNo)) {
                $this->repostAndCommentDiary($diaryInfo);
            }
            
        }

        // 达人升级
        $this->autoUidModel->updateAbilityLevel($diaryInfo['uid']);

        //发视频审核不进点滴列表、lbs
        if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1){
            $this->sendReviewQueue($diaryInfo, $user);
        }else{
            // 点滴进lbs点滴列表
            $this->addDiaryLbs($diaryInfo['geo'], $diaryInfo['bodyId'], $diaryInfo['uid']);
            // 点滴进话题
            $this->sendDiaryToTopic($diaryInfo['topic_id'], $diaryInfo['topics'], $diaryInfo);
        }
        
        // 异步反垃圾分析
        $this->sendDiaryToClassify($diaryInfo);
        RedisPool::addUserEventCreateJob('postDiray', UK::JsonFormat([ 'e'=>'postDiray', 'c'=>['uid'=>intval($diaryInfo['uid']), 'bodyId'=>intval($diaryInfo['bodyId'])] ]) );
        
        return  $result;
    }

	public function editDiary($diaryInfo){

		$bodyId = $diaryInfo['bodyId'];
		if(!$bodyId){
			return false;
		}
		// 检查是否被禁言
		$status  =  $this->autoUidModel->checkUserStatus(AC::$hostUserBaseInfo);
		if (!empty(AC::$errorNo)){
			return  false;
		}
		if (AC::HOST_UID != $diaryInfo['uid']){
			AC::$errorNo    =   'UC010';
			return  false;
		}

		$max_numbers = AC::$hostUserBaseInfo['max_numbers'] * 3;
		// 字符串截取
		$diaryInfo['content'] = UK::getstr($diaryInfo['content'], $max_numbers);
		$diaryInfo['title']   = UK::getstr($diaryInfo['title'], 120, '', 1);

		if (strlen($diaryInfo['content']) < 1){
			AC::$errorNo    =   'DC001';
			return  false;
		}

		// 判别是否重复提交
		if (empty($diaryInfo['data_action'])) {
			$ck = $this->diaryListModel->checkLastContent($diaryInfo);
			if (AC::$errorNo){
				UK::varDump(AC::$errorNo, __METHOD__);
				return  false;
			}
		}

		// 更新用户活跃时间
		$this->autoUidModel->updateUserLastActivity($diaryInfo['uid']);

		//带有视频的点滴，标记类型type=1
		unset($diaryInfo['diaryType']);
		if (isset($diaryInfo['video']) && isset($diaryInfo['video'][0]) && is_array($diaryInfo['video'][0])){
			$diaryInfo['diaryType'] = 1;
			//检查用户发视频权限
			$user = $this->checkUserPostVideoAccess($diaryInfo['uid']);
			if (AC::$errorNo){
				return false;
			}
		}



		$diaryId    =   $this->diaryBodyModel->getDiaryId($bodyId);
		if(!$diaryId)
		{
			return false;
		}
		$diaryInfo = $this->updateExtend($diaryInfo,$bodyId);

		$diaryRes   =   $this->diaryBodyModel->updateDiaryBody($diaryInfo,$diaryId);

		if (!$diaryRes)
		{
			UK::varDump(AC::$errorNo, __METHOD__);
			return  false;
		}

		$this->diaryListCacheModel->setLastCheckConnent($diaryInfo['uid'], $ck);


		//发视频到审核列表
		if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1){
			$diaryVideoModel = new DiaryVideoModel();
			$diaryVideo = $diaryInfo;
			$user['verified'] && $diaryVideo['rate'] = 0;
			$diaryVideoModel->deleteDiaryVedioByBodyud($diaryVideo['bodyId'], $diaryVideo['uid']);
			$diaryVideoModel->addDiaryVideo($diaryVideo);
			unset($diaryVideo);
		}

		// 写附件信息
		$diaryMsg = $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);

		# true不更新false需要更新
		$attachmentRes = $this->checkAttachment($diaryMsg['attachmentList'],$diaryInfo['attachment']);
		$voiceRes  = $this->checkAttachment($diaryMsg['voiceList'],$diaryInfo['voice']);
		$videoRes  = $this->checkAttachment($diaryMsg['videoList'],$diaryInfo['video']);
		$linkRes   = $this->checkAttachment($diaryMsg['linkList'],$diaryInfo['link']);
		if(!$attachmentRes || !$voiceRes || !$videoRes || !$linkRes){
			$res = $this->delDiaryAttachment($bodyId,AC::HOST_UID);
			$this->addDiaryAttachment($diaryInfo);
		}

		$diaryListUpdate=   $this->diaryListModel->updateDiaryList($diaryInfo);

		if (empty($diaryListUpdate))
		{
			UK::varDump(AC::$errorNo, __METHOD__);
			return  FALSE;
		}

		$result =   array('bodyId' => $diaryInfo['bodyId']);

		$this->diaryListCacheModel->delDiaryCache($diaryInfo['bodyId']);

		//将日志加入redis缓存
		$this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);


		//发视频审核不进点滴列表、lbs
		if (isset($diaryInfo['diaryType']) && $diaryInfo['diaryType']==1 && !$user['verified']){
			AC::$feedInfo['diaryVideoNeedReview'] = 1;//标记视频需要审核
			$video_info = explode(',', $diaryInfo['video'][0]['info']);
			$video_sec = (int)($video_info[0]/1000);
			$video_url = $diaryInfo['video'][0]['path'];
			RedisPool::addDiaryReviewGearmanJob('identify_upyun', [
				'bodyId'=>$diaryInfo['bodyId'], 'sec'=>$video_sec, 'url'=>$video_url
			]);
		}

		return  $result;
	}


	public function updateExtend($diaryInfo,$bodyId){

		$diarybodyInfo = $this->diaryBodyModel->getDiaryBody($diaryInfo['uid'], $bodyId);
		if(!empty($diarybodyInfo['extend'])){
			$extend = json_decode($diarybodyInfo['extend'],true);
			$extend['original'] = $diaryInfo['original']?$diaryInfo['original']: '0';
		}else{
			$extend['original'] = $diaryInfo['original']?$diaryInfo['original']: '0';
		}
		$diaryInfo['extend']  = json_encode($extend);

		$diaryListInfo = $this->diaryListModel->getDiaryListInfoByBodyId($bodyId);
		if(!empty($diaryListInfo['extras'])){
			$extras = json_decode($diaryListInfo['extras'],true);
			$extras['original'] = $diaryInfo['original']?$diaryInfo['original']:'0';
		}else{
			$extras['original'] = $diaryInfo['original']?$diaryInfo['original']:'0';
		}
		$diaryInfo['extras']  = json_encode($extras);
		return $diaryInfo;
	}

	public function  checkAttachment($attachmentList,$sendAttachmentList){
		$attachmentListCount = 	count($attachmentList);
		$sendAttachmentListCount = count($sendAttachmentList);
		if($attachmentListCount != $sendAttachmentListCount){
			return false;
		}
		if($attachmentListCount==0 && $sendAttachmentListCount==0){
			return true;
		}
		$attachmentPathList = array();
		foreach ($attachmentList as $val){
			$attachmentPathList[]=$val['attachmentPath'];
		}
		foreach ($sendAttachmentList as $value){
			if(!in_array($value['path'],$attachmentPathList)){
				return false;
				break;
			}
		}
		return true;
	}

    private function sendReviewQueue($diaryInfo, $user){
        AC::$feedInfo['diaryVideoNeedReview'] = 1;//标记视频需要审核
        $video_info = explode(',', $diaryInfo['video'][0]['info']);
        $video_sec = (int)$video_info[0];
        $video_url = $diaryInfo['video'][0]['path'];
        RedisPool::addDiaryReviewGearmanJob('identify_upyun', [
            'bodyId'=>$diaryInfo['bodyId'], 'sec'=>$video_sec, 'url'=>$video_url,
            'review'=>$user['verified'] ? 0 : 1 //加v用户判断,0-不需要审核,1-需要
        ]);
    }

    private function checkUserPostVideoAccess($uid){
        $user = $this->autoUidModel->getUserInfo($uid);
        if (empty($user)){
            AC::$errorNo = 'UC010';
            return false;
        }
//        if($user['is_ability'] || $user['verified'] || $user['is_vip']){}
        if($user['level']>=6 || $user['is_ability'] || $user['verified'] || $user['is_vip']){}
        else{
            AC::$errorNo = 'UC040';//只有六级及其以上、达人、加V用户,会员才能发送视频
            return false;
        }
        $today_post_video_count_ckey = 'tpvc:'.$uid;
        $today_post_video_count = (int)$this->diaryListCacheModel->getStringByKey($today_post_video_count_ckey);
        if ($today_post_video_count>10){
            AC::$errorNo = 'UC041';//超过当日发送视频次数限制
            AC::$errorMsg = '今天发表视频次数已达上限';
            return false;
        }
        $today_post_video_count ++;
        $cttl = strtotime(date('Y-m-d',strtotime('+1 day'))) - AC::SERVER_TIME;
        $this->diaryListCacheModel->addStringByKey($today_post_video_count_ckey, $today_post_video_count, $cttl);
        return $user;
    }
    
    	/**
	 * 用户投票
	 * @param unknown $info
	 * @return boolean
	 */
	public function voteDiary($info){
		// init params
		isset($info['uid'])           &&    $host_id  =    intval($info['uid']);
		isset($info['tid'])           &&    $bodyId   =    intval($info['tid']);
		isset($info['voteids'])       &&    $oid      =    $info['voteids'];
		// check params
		if ($host_id < 1 || $bodyId < 1){
			AC::$errorNo    =   'GRC001';
			return false;
		}

		// 是否是本人登录
		if ($host_id != AC::HOST_UID){
			AC::$errorNo    =   'GRC005';
			return false;
		}

		//判断日记是否存在
		$body = $this->getDiaryWithComments(array('bodyId' => $bodyId));
		if(empty($body)){
			AC::$errorNo = 'GRC002';
			return false;
		}

		//检测是否添加投票
		if($body['bodyInfo']['vote'] == 0){
			AC::$errorNo = 'GRC009';
			return false;
		}
		//初始化传参条件
		$author_uid = $body['bodyInfo']['uid'];

		//获取投票表信息
		$voteLinkInfo = $this ->voteModel->getVoteLinkInfo($bodyId);
		if(empty($voteLinkInfo) || $voteLinkInfo['status'] == 2){
			AC::$errorNo = 'GRC010';
			return false;
		}

		//判断选项是否超出最大选大选项
		$max_options = count($oid);
		if($voteLinkInfo['max_options'] < $max_options){
			AC::$errorNo = 'GRC005';
			return false;
		}

		//获取选项表信息
		$voteOptionsInfo = $this->voteModel->getVoteOptions($bodyId,$author_uid, $host_id);
		//数据拆分
		$isvoted = $voteOptionsInfo['isvoted'];
		$vid = $voteLinkInfo['id'];
		$list = $voteOptionsInfo['list'];
		if($isvoted){
			AC::$errorNo    =   'GRC006';
			return false;
		}
		//添加投票
		$result = $this->voteModel->addTopicVoteLogs($oid,$host_id,$author_uid,$bodyId, $vid);
		return $result;
	}
    /**
     * 组装日记topics
     * @param unknown $topic_id
     * @return boolean|string
     */
    private function assembleDiaryTopics ($topic_id) {
        $topics = '';
        if($topic_id) {
            $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($topic_id);
            $this->checkDiaryTopicIsValid($diaryTopic);
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
                return FALSE;
            }
            
            $topics = UK::var_json_encode(array('gid' => $topic_id, 'name' => $diaryTopic['name'], 'type' => $diaryTopic['type']));
        }
        
        return $topics;
    }
    
    /**
     * 验证点滴话题有效性
     * @param unknown $topic
     * @return boolean
     */
    private function checkDiaryTopicIsValid ($topic) {
        if (empty($topic)) {
            AC::$errorNo = 'DTC002';
            return false;
        }else{
            if ($topic['status'] == AC::$diaryTopicCf['delete_status']){
                AC::$errorNo = 'DTC003';
                return false;
            }
        }
        
        return true;
    }
    
    /**
     * 获取信纸id
     * @param unknown $paper
     * @return Ambigous <number, string>
     */
    private function assembleDiaryPaperId (&$paper) {
        $pid = 0;
        if ($paper){
            $pos = strpos($paper, '_');
            if ($pos == 5) {
                $pid = substr($paper, 0, 5);
            }else{
                $paper = '';
            }
        }
        
        return $pid;
    }

    /**
     * 根据extend字段赋值extras
     * @param $extras
     * @param $extend
     */
    private function assembleDiaryListExtrasFromExtend (&$extras, $extend) {
        if(empty($extend))return;
        if ($extend_arr = json_decode($extend, true)){
            if (empty($extend_arr['vip']['cardbg']) && empty($extend_arr['source'])){
                return;
            }
            $extras_arr = json_decode($extras, true);
            if (empty($extras_arr)){
                $extras_arr = [];
            }
            if (!empty($extend_arr['vip']['cardbg'])){
                $extras_arr['vip']['cardbg'] = $extend_arr['vip']['cardbg'];
            }
            if (!empty($extend_arr['source'])){
                $extras_arr['source'] = $extend_arr['source'];
            }
            if (!empty($extend_arr['original'])){
				$extras_arr['original'] = $extend_arr['original'];
			}else{
				$extras_arr['original'] = '';
			}
            $extras_arr && $extras = UK::JsonFormat($extras_arr);
        }
    }
    
    /**
     * 组装字段值
     * @param unknown $uid
     * @param unknown $pid
     * @param unknown $content
     * @param unknown $paper
     * @return string
     */
    private function assembleDiaryExtend($uid, $pid, $content, &$paper, $diaryInfo = []) {
        $extend = '';
        
        // 匹配日记内容，找出匹配到的全部表情的id列表
        $paper_emotion_ids_mebuy = array();
        $matched_emotion_ids     = Emotion::matchEmotionIdList($content);
        $effective_ids           = $matched_emotion_ids;
        if (empty(AC::$iosFullVersion)) {
            if ($matched_emotion_ids || $pid){
                // 获取我已购买的全部信纸、表情
                $paper_emotion_ids_mebuy = $this->shopModel->getShopIdListMeBuy($uid);
                if (!in_array($pid, $paper_emotion_ids_mebuy)){
                    $paper = '';
                }
            }
            $effective_ids       = array_intersect($paper_emotion_ids_mebuy, $matched_emotion_ids);
        }
        
        // 以json格式存储到数据库中
        if (is_array($effective_ids) && count($effective_ids) > 0){
            $extend = array('shop_ids_mebuy' => $effective_ids);
        }
        $cardbg = trim($diaryInfo['cardbg']);
        $vip = $this->autoUidModel->getUserVipInfo($uid);
        if ($vip){
            if ($cardbg){
                $extend['vip']['cardbg'] = $cardbg;
            }else{
                $extend['vip']['cardbg'] = '/diary/card/140012/2.png';//默认卡片背景
            }
        }
        if (isset($diaryInfo['device_id'])){
            $diaryInfo['device_id'] = intval($diaryInfo['device_id']);
            if ($diaryInfo['device_id']>0){//用户设置了机型
                $userNodel = new UserModel();
                $device_text = $userNodel->getDeviceTextById($diaryInfo['device_id']);
                $extend['source'] = $device_text;
            }else{//用户使用自定义
                if ($vip){
                    $extend['source'] = $vip['diy_source'];
                }else{
                    $extend['source'] = '';
                }
            }
        }else{
            $extend['source'] = '';
        }
        if($diaryInfo['original']=='1'){

			$extend['original'] = '1';

		}else{
        	if($diaryInfo['original']){
				$extend['original'] = UK::getstr($diaryInfo['original'],15);
			}else{
				$extend['original'] = '';
			}
		}

        $extend && $extend = UK::JsonFormat($extend);
        return $extend;
    }
    
    /**
     * 写附件
     * @param unknown $diaryInfo
     * @return boolean
     */
    private function addDiaryAttachment ($diaryInfo) {
        if (AC::$errorNo) return false;

        $diaryInfo['type']    = 1;
        $diaryInfo['type_id'] = $diaryInfo['bodyId'];

        $userService = new UserService();
        $user = $userService->getUserInfo($diaryInfo['uid'], AC::HOST_UID);

        $attachmentService = new AttachmentService();
        $attachmentService->saveDiaryAttachment($diaryInfo, $user);

        AC::$errorNo = '';
        return true;
    }
	public function delDiaryAttachment($bodyId,$uid){
		$attachmentService = new AttachmentService();
		$res = $attachmentService->delDiaryAttachment($bodyId, $uid);
		return $res;
	}
    /**
     * 组装传值geo信息
     * @param unknown $reqgeo
     * @return Ambigous <multitype:, multitype:NULL string >
     */
    private function assembleDiaryGeo ($reqgeo) {
        $geo = array();
        if(is_array($reqgeo)){
        
            $cityid =   $this->lbsModel->getCityIdByCityCode($reqgeo['province'], $reqgeo['city'], $reqgeo['region']);
            if($cityid > 0){
                $geo =   $this->filterDataOfGeo($reqgeo);
            }
        }
        
        return $geo;
    }
    
    /**
     * 将点滴添加进话题点滴列表
     * @param unknown $topic_id
     * @param unknown $topics
     * @param unknown $diaryInfo
     * @return boolean
     */
    public function sendDiaryToTopic ($topic_id, $topics, $diaryInfo) {
        if (empty($topic_id) || empty($topics) || AC::$errorNo) {
            return false;
        }
        
        $tmp = array(
            'gid'     => $diaryInfo['topic_id'],
            'uid'     => $diaryInfo['uid'],
            'bodyId'  => $diaryInfo['bodyId'],
            'title'   => $diaryInfo['title'],
            'content' => $diaryInfo['content']
        );
        $this->topicModel->addDiaryToTopic($tmp);
        AC::$errorNo = '';
    }
    
    /**
     * 反垃圾收集
     * @param unknown $diaryInfo
     */
    private function sendDiaryToClassify ($diaryInfo) {
        $classifyData = array(
            'uid'         =>    strval($diaryInfo['uid']),
            'target'      =>    'diary',
            'targetId'    =>    strval($diaryInfo['bodyId']),
            'text'        =>    array(
                                    'title'	  =>	strval($diaryInfo['title']),
                                    'content' =>	strval($diaryInfo['content'])
                                ),
            'attachments' =>	array(
                                    'images'  =>	$diaryInfo['attachment'],
                                    'voices'  =>	$diaryInfo['voice']
                                ),
            'extra'       =>    array(
                                    'bodyId'  =>    strval($diaryInfo['bodyId']),
                                    'label'   =>    strval($diaryInfo['label']),
                                    'secret'  =>    strval($diaryInfo['secret']),
                                    'zfBodyId'=>    strval($diaryInfo['zfBodyId']),
                                    'zfUid'   =>    strval($diaryInfo['zfUid'])
                                ),
            'version'     =>    AC::$antispam_version
        );
        $classifyDataOfJson = json_encode($classifyData);
        RedisPool::addClassifyGearmanJob("classify", $classifyDataOfJson);
    }
    
    private function filterDataOfGeo($geo){
        if(empty($geo['province']) || empty($geo['city'] || $geo['region'] || $geo['latitude'] || $geo['longitude'])){
            return array();
        }
        $geo=array(
            'province'  =>  UK::getstr($geo['province'], 20),
            'city'      =>  UK::getstr($geo['city'], 50),
            'region'    =>  UK::getstr($geo['region'], 50),
            'address'   =>  UK::getstr($geo['address'], 128),
            'latitude'  =>  UK::getstr($geo['latitude'], 20),
            'longitude' =>  UK::getstr($geo['longitude'], 20),
        );
        return $geo;
    }
    
  
    public function addDiaryLbs($geo, $bodyId, $uid){
        if(empty($geo['city']) || empty($geo['latitude']) || empty($geo['longitude']))  return false;
         
            $geo['typeid'] = $bodyId;
            $geo['uid']    = $uid;      
            $this->lbsModel->addDiaryGeo($geo,AC::LBS_TYPE_DIARY);

        return true;
    }
    
    private function restructShareData ($diaryInfo, $uid) {
        $diaryData      = array();
        $pattern        = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i";
        $action         = UK::getstr($diaryInfo['data_action'], 512,'',1);
        $action_arr     = parse_url($action);
        
        $diaryData = array(
                'uid'    =>    $uid,
                'title'  =>    $diaryInfo['title'],
                'content'=>    $diaryInfo['content']
        );
        if (in_array($action_arr['scheme'], array('http', 'https', 'pinkwx'))){
            $tmp = array(
                    'url_title'        =>    UK::getstr($diaryInfo['data_title'], 120,'',1),
                    'url_content'      =>    UK::getstr($diaryInfo['data_content'], 512,'',1),
                    'url_type'         =>    'web',
                    'url_image'        =>    UK::getstr($diaryInfo['data_image'], 200,'',1),
                    'url_action'       =>    $action,
                    'url_type_uid'     =>    $uid,
            );
            $diaryData['extras']['web'][]	=	$tmp;
            $diaryData['extras']            =   UK::var_json_encode($diaryData['extras']);
        }else{

            $parr = array();
            $action_pre = $action;
            if (!empty($action_arr['query'])){
                $action_pre = substr($action, 0, -strlen($action_arr['query']));
                parse_str($action_arr['query'],$parr);
            }
            
            if (in_array($action_pre, AC::$openUrl)) {
                if ($action_pre == AC::$openUrl ['group_topic']) {
                    $tid            =    intval($parr['tid']);
                    $gid            =    intval($parr['gid']);
                    $author_uid     =    intval($parr['uid']);
                    if ($tid < 1 || $gid < 1 || $author_uid < 1){
                        AC::$errorNo = 'GRC001';
                        return FALSE;
                    }
                    
                    // 从redis中查找圈子信息
                    $groupInfo  =   $this->groupInfoModel->groupAddRedis($gid);
                    if (empty($groupInfo)){
                        AC::$errorNo = 'GRC002';
                        return FALSE;
                    }
                    
                    // 查看话题
                    $topic      =   $this->topicModel->topicAddRedis(array('tid' => $tid));
                    if (empty($topic)){
                        AC::$errorNo = 'GRC002';
                        return FALSE;
                    }
                     
                    // 判断数据
                    if ($gid != $topic['gid']){
                        return FALSE;
                    }
                    
                    // 获取用户详情
                    $userInfo = $this->autoUidModel->getUserInfo($uid);
                    if (empty($userInfo)){
                        return FALSE;
                    }
                    
                    // 获取话题内容
                    $topicComment = $this->topicCommentsModel->getCommentUid(array('tid' => $topic['tid'], 'author_uid' => $topic['uid'], 'position' => 1));
                    $diaryData = array(
                            'uid'    =>    $uid,
                            'nickname' =>  $userInfo['nickname'],
                            'title'  =>    $topic['title'],
                            'content'=>    $topicComment['content']
                    );
                    $tmp = array(
                            'url_type'         =>    'topic',
                            'url_type_id'      =>    $topic['tid'],
                            'url_type_uid'     =>    $uid,
                    );
                    $diaryData['extras']['topic'][]	=	$tmp;
                    $diaryData['extras']            =   json_encode($diaryData['extras']);
                }else if ($action_pre == AC::$openUrl ['article_info']) {
                    $aid            =    intval($parr['aid']);
                    $author_uid     =    intval($parr['author_uid']);
                    //获取文章内容
                    $articleModel = new ArticleService();
                    $articleInfo = $articleModel->getArticleInfo($aid, $author_uid);

                    $summary = UK::cleanStrStrict($articleInfo['summary']);
                    $title   = UK::cleanStrStrict($articleInfo['title']);
                    if(empty($summary)) {
                        $content = UK::checkHTMLContent($articleInfo['content']);
                        $summary = UK::getstr($content, AC::ARTICLESUMMARYLENGTH,'',2);
                    }

                    $tmp = array(
                            'url_title'         =>  $title,
                            'url_content'       =>  $summary,
                            'url_image'         =>  $articleInfo['cover'],
                            'url_action'        =>  $action,
                            'url_type'          =>  'article',
                            'url_type_id'       =>  $articleInfo['aid'],
                            'url_type_uid'      =>  $author_uid,
                            'url_extend'        =>  array(
                                'cover'     =>      $articleInfo['cover'],
                                'uid'           =>  $author_uid,
                                'nickname'      =>  $articleInfo['user']['nickname'],
                                'avatar'        =>  $articleInfo['user']['avatar']
                            ),
                    );
                    //为保证文章能正确解析，此处多进行一次base64_encode!,使用时注意解析！
                    $diaryData['extras']['article'][]	=	base64_encode(json_encode($tmp,JSON_UNESCAPED_UNICODE));
                    $diaryData['extras']            =   json_encode($diaryData['extras'],JSON_UNESCAPED_UNICODE);
                }else{
                    $tmp = array(
                            'url_title'        =>    UK::getstr($diaryInfo['data_title'], 120,'',1),
                            'url_content'      =>    UK::getstr($diaryInfo['data_content'], 512,'',1),
                            'url_type'         =>    'web',
                            'url_image'        =>    UK::getstr($diaryInfo['data_image'], 200,'',1),
                            'url_action'       =>    $action,
                            'url_type_uid'     =>    $uid,
                    );
                    $diaryData['extras']['app'][]	=	$tmp;
                    $diaryData['extras']            =   UK::var_json_encode($diaryData['extras']);
                }
            }
        }
        
        return $diaryData;
    }
    
    /**
     * 转发并评论
     * @param unknown $diaryInfo
     */
    private function repostAndCommentDiary ($diaryInfo) {
        $zfcontent = '转发了这条日记';
        if (isset($diaryInfo['commentContent']) && $diaryInfo['commentContent']) {
            $zfcontent = strval($diaryInfo['commentContent']);
        }else{
            return ;
        }

        $this->addCommentInfo(AC::HOST_UID, $diaryInfo['zfUid'], $diaryInfo['zfBodyId'], $zfcontent);
        if (AC::$errorNo) AC::$errorNo;
    }
    
    /**
     * 评论日记
     * @param unknown $commentInfo
     * @return boolean|unknown
     */
    private function addCommentInfo($uid, $cUid, $bodyId, $content){
        if (empty($uid)  ||  empty($cUid)) {
            return  FALSE;
        }
        
        $access =   $this->checkAccessPremission($cUid);
        if (empty($access)) return  FALSE;
    
        $userBaseInfo       =   $this->autoUidModel->getUserInfo($uid);
        if (!isset($userBaseInfo['nickname'])) {
            return  FALSE;
        }

        $cUidBaseInfo       =   $this->autoUidModel->getUserInfo($cUid);
        if (!isset($cUidBaseInfo['nickname'])) {
            return  FALSE;
        }
        
        $commentInfo = array(
            'uid'         =>  $uid,
            'cUid'        =>  $cUid,
            'bodyId'      =>  $bodyId,
            'nickname'    =>  $userBaseInfo['nickname'],
            'cNickname'   =>  $cUidBaseInfo['nickname'],
            'content'     =>  $content,
            'type'        =>  1,
            'rUid'        =>  0,
            'parentId'    =>  0,
            'rNickname'   =>  ''
        );

        $diaryInfo  =   $this->diaryListModel->getDiaryInfoByBodyId($bodyId);
        if (empty($diaryInfo['uid'])) return  FALSE;
        if ($uid !=  $cUid) {
            if (!empty($diaryInfo['secret'])) return  FALSE;
        }
        
        $quote = empty($diaryInfo['title']) ? $diaryInfo['abbreviation']:$diaryInfo['title'];
        
        // 新点滴
        if ($diaryInfo['time'] >= AC::$diaryCommentCf['transfer_time'] && empty(AC::$errorNo)) {
            $data = $this->assembleTopicCommentData($commentInfo, $diaryInfo);

            $commentId = $this->topicCommentsModel->commentDrab($data);
            AC::$errorNo = '';
        }
        
        $result =   $this->commentModel->postComment($commentInfo);
        if (empty($result)) {
            AC::$errorNo = NULL;
            return  FALSE;
        }
        $result['avatar']    =    $userBaseInfo['avatar'];
    
        $comment = $this->CommnetInfo($result);
    
        #  feed & statistics
        AC::$userStatistics[$uid]['commentTimes']    =   1;
        AC::$userStatistics[$cUid]['commentMeTimes'] =   1;
        if($uid != $cUid) {
            AC::$userStatistics[$cUid]['newCommentTimes']=   1;
            AC::$userStatistics[$cUid]['newLikeMeTimes'] =   1;
            AC::$userStatistics[$cUid]['newCommentMeTimes'] =   1;
        }
        
        // 关于我的轮询计数
        if (isset(AC::$bodyidTypeClass[$commentInfo['type']]) && $commentId) {
            $set = [
                'uid' => $data['author_uid'],
                'bodyId' => $data['tid'],
                'commentTimes' => (int)$commentId
            ];
            $this->diaryListModel->setDiaryList($set);
            $this->diaryListCacheModel->delDiaryCache($set['bodyId']);
            /*AC::$itemStatistics =   array(
                'commentTimes'      =>  1,
                'bodyidTypeClass'   =>  AC::$bodyidTypeClass[$commentInfo['type']],
                'uid'               =>  $cUid,
                'bodyId'            =>  $commentInfo['bodyId'],
                'kitType'           =>  $commentInfo['type']
            );*/
        }
        if (!empty($diaryInfo['secret']))   return  $comment;

		// 推送
        if($uid != $cUid) {
            $push	=	new PushController();
            $push->push($commentInfo, "pushComment");
        }
        return  $comment;
    }/*}}}*/
    
    private function assembleTopicCommentData ($param, $diaryInfo) {
        $topics          =   $this->diaryListModel->getDiaryTopic($diaryInfo['topics']);
        $data = array(
            'uid'        =>  $param['uid'],
            'tid'        =>  $param['bodyId'],
            'gid'        =>  $topics[0]['id'] ? $topics[0]['id'] : AC::$diaryCommentCf['diary_topicid'],
            'nickname'   =>  $param['nickname'],
            'author_uid' =>  $param['cUid'],
            'author_name'=>  $param['cNickname'],
            'content'    =>  $param['content']
        );
        
        return $data;
    }
        
    // 组装评论返回信息
    private function CommnetInfo($info){
        $commentInfo = array();
        $commentInfo['id']          =        strval($info['id']);
        $commentInfo['uid']         =        strval($info['uid']);
        $commentInfo['cUid']        =        strval($info['cUid']);
        $commentInfo['cNickname']   =        $info['cNickname'];
        $commentInfo['avatar']      =        $info['avatar'];
        $commentInfo['rUid']        =        strval($info['rUid']);
        $commentInfo['rNickname']   =	     $this->autoUidModel->getRemarkName(array('uid'=>$info['rUid'],'nickname'=>$info['rNickname']));
        $commentInfo['bodyId']      =        strval($info['bodyId']);
        $commentInfo['parentId']    =        strval($info['parentId']);
        $commentInfo['type']        =        strval($info['type']);
        $commentInfo['content']     =        $info['content'];
        $commentInfo['commentType'] =        '1';
        $commentInfo['time']        =        strval(AC::SERVER_TIME);
        $commentInfo['replyTime']   =        strval(AC::SERVER_TIME);
        $commentInfo['replyNum']    =        '1';
        $commentInfo['status']      =        '0';
    
        return $commentInfo;
    }

    public function setDiary($diaryInfo)/*{{{*/
    {
        // 是否禁言
        $status  =  $this->autoUidModel->checkUserStatus(AC::$hostUserBaseInfo);
        if (!empty(AC::$errorNo)){
            return  FALSE;
        }
        
        if (isset($diaryInfo['content'])){
        	$diaryInfo['content'] = UK::getstr($diaryInfo['content'], AC::$hostUserBaseInfo['max_numbers']);
        }
        $diaryInfo['title'] = UK::getstr($diaryInfo['title'], 120, '', 1);
        if (strlen($diaryInfo['title'])< 1  &&  strlen($diaryInfo['content']) < 1    &&  empty($diaryInfo['attachment']) && !isset($diaryInfo['secret']))
        {
            AC::$errorNo    =   'DC006';
            return  FALSE;
        }
        $info   =   $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);
        if (empty($info) || $info['uid'] != AC::HOST_UID)
        {
            AC::$errorNo    =   'DC004';
            return  FALSE;
        }
        $this->diaryListModel->setDiaryList($diaryInfo);
        $this->diaryBodyModel->setDiaryBody($diaryInfo);
        #   $this->diaryAttachmentModel->setDiaryAttachment($diaryInfo);
        if (!empty(AC::$errorNo))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        #redis 修改日志时删除旧的缓存,将新数据加入缓存
        $this->diaryListCacheModel->delDiaryCache($diaryInfo['bodyId']);
        $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);
        $secret =   0;
        if (!empty($diaryInfo['secret']))   $secret =   1;
        if ($info['secret'] !=  $secret)
        {
            $statistics                     =   $this->userStatisticsModel->getUserStatistics(array('uid' => $diaryInfo['uid']));
            $data['uid']                    =   $diaryInfo['uid'];
            if (1   ==  $secret)
            {
                $data['diaryTimes']         =   $statistics['diaryTimes'] - 1;
                $data['secretDiaryTimes']   =   $statistics['secretDiaryTimes'] + 1;
                $this->diaryListCacheModel->delDiarySquare($info);
            }
            else
            {
                $data['diaryTimes']         =   $statistics['diaryTimes'] + 1;
                $data['secretDiaryTimes']   =   $statistics['secretDiaryTimes'] - 1;
            }
            if ($data['diaryTimes'] < 1)        $data['diaryTimes'] =   0;
            if ($data['secretDiaryTimes'] < 1)  $data['secretDiaryTimes']   =   0;
            $this->userStatisticsModel->setUserStatistics($data);
        }
        if ($secret){
            $top = $this->getDiaryTopBodyids($info['uid']);
            $top && in_array($diaryInfo['bodyId'], $top) && $this->diaryRemoveTop($diaryInfo);
        }
        return  TRUE;
    }/*}}}*/

    public function videoPlay($param){
        if (empty($param['bodyId']))
        {
            AC::$errorNo    =   'DC005';
            return  FALSE;
        }
        empty($param['uid']) && $param['uid'] = 1;
        return $this->countTimes(array('uid' => $param['uid'], 'bodyId' => $param['bodyId'], 'viewTimes' => 1));
    }

    public function countTimes($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DC005';
            return  FALSE;
        }
        $result =   $this->diaryListModel->countTimes($diaryInfo);
        
        return  $result;
    }/*}}}*/

    public function removeDiary($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DC007';
            return  FALSE;
        }
        
        $info =  $this->diaryListModel->getDiaryListInfo($diaryInfo);
        if (empty($info)){
            AC::$errorNo=   'COC006';
            return  FALSE;
        }
        $result = $this->diaryListModel->removeDiaryList($diaryInfo);
        $this->diaryBodyModel->removeDiaryBody($diaryInfo);
        $this->diaryAttachmentModel->removeDiaryAttachment($diaryInfo);
        // 删除日志时redis中也删除日志缓存
        $this->diaryListCacheModel->removeDiaryAll($diaryInfo['bodyId'], $diaryInfo['uid'], $info['label']);
        //删除LBS
        $this->lbsModel->removeDiaryGeo($diaryInfo);
        if ($info['topics']) {
            $topics = $this->diaryListModel->getDiaryTopic($info['topics']);
            if ($topics && $topics[0]['id']) {
                $this->diaryListCacheModel->removeTopicDiaryOfList($topics[0]['id'], $diaryInfo['bodyId']);   
            }
            
            $this->topicModel->removeTopicDiary($diaryInfo['bodyId']);
        }
        
        // 判断出现错误吗,或者数据库删除失败
        if (!empty(AC::$errorNo))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        if (!empty($diaryInfo['secret']))
        {
            AC::$userStatistics[$diaryInfo['uid']]['secretDiaryTimes']  =   -1;
        }
        else
        {
            AC::$userStatistics[$diaryInfo['uid']]['diaryTimes']        =   -1;
        }
        return  TRUE;
    }/*}}}*/

    private function getDiaryInfoDetail($diaryInfo)/*{{{*/
    {
        if (empty($diaryInfo['uid']) || empty($diaryInfo['bodyId']))
        {
            AC::$errorNo    =   'DC003';
            return  FALSE;
        }

        #   access = FALSE  don't have premission to access this!
        $access =   $this->checkAccessPremission($diaryInfo['uid']);
        if (empty($access)) return  FALSE;

        $listInfo   =   $this->diaryListModel->getDiaryInfoByBodyId($diaryInfo['bodyId']);
        if (empty($listInfo) || $listInfo['status'] != 0)
        {
            AC::$errorNo    =   'DC004';
            return  FALSE;
        }
        $listInfo['viewTimes'] = strval($listInfo['likeTimes'] + $listInfo['commentTimes'] + $listInfo['viewTimes'] + $listInfo['repostTimes']);        
        if (1   ==  $listInfo['secret'])
        {
            if (AC::HOST_UID    !=  $diaryInfo['uid'])
            {
                AC::$errorNo    =   'DC008';
                return  FALSE;
            }
        }
        
        // 转发的分享结构
        $structData = array();
        if($listInfo['extras']){
            $structData = $this->diaryListModel->structData($listInfo);
            if (!empty($structData)) {
                //$listInfo['viewTimes']      =    strval($structData['viewTimes']);
                unset($structData['viewTimes']);
            }
        }
        $listInfo['url_struct']    =    array();
        if (!empty($structData)){
            $listInfo['url_struct'][] = $structData;
        }
        unset($listInfo['extras']);
        
        $attachment =   array();
        if (!empty($listInfo['attachmentPath']))
        {
            $attachment =   $this->diaryAttachmentModel->getDiaryAllAttachment($diaryInfo);
        }

        $bodyInfo   =   $this->diaryBodyModel->getDiaryBody($diaryInfo['uid'], $diaryInfo['bodyId']);
        if (!empty(AC::$errorNo))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 返回信纸地址
        if (isset($bodyInfo['paper_url'])){
            $bodyInfo['paper_url'] = $this->generatePaperUrl($bodyInfo['paper_url']);
        }
        
        $user = $this->autoUidModel->getUserInfo($diaryInfo['uid'],'',AC::HOST_UID);
        $user['nickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$user['uid'],'nickname'=>$user['nickname']));

        $data['uid']        =   $diaryInfo['uid'];
        $data['bodyId']     =   $diaryInfo['bodyId'];
        $data['viewTimes']  =   1;
        $result =   $this->countTimes($data);
        // 语音功能判断老版本
        $bodyInfo['content'] = UK::tipsUpgrade($attachment['voiceList'], $bodyInfo['content'], 'voice');
        // 表情对应的列表
        $emotion_ids_mebuy = array();
        if ($bodyInfo['extend']){
            $extend_arr = json_decode($bodyInfo['extend'], TRUE);
            $emotion_ids_mebuy = $extend_arr['shop_ids_mebuy'];
        }
        if (empty($emotion_ids_mebuy) && $bodyInfo['saveTime'] < Emotion::$filter_emotion_update_time){
            $emotion_ids_mebuy = Emotion::$default_emotion_ids;
        }
        
        $bodyInfo['imageList'] = Emotion::emotionToImgList($bodyInfo['content'], $emotion_ids_mebuy);
        $bodyInfo['content']   = Emotion::emotionToMark($bodyInfo['content'], $emotion_ids_mebuy);
        unset($bodyInfo['extend']);
        
        // 限制附件显示数量
        $attachment['attachmentList'] = array_slice($attachment['attachmentList'], 0, AC::$topicDiaryAttachmentLimit );
        // 增加了语音附件
        return  array('bodyInfo' => $bodyInfo, 'attachment' => $attachment['attachmentList'], 'voiceList'=> $attachment['voiceList'],'listInfo' => $listInfo,'user'=>$user);
    }/*}}}*/

    private function checkAccessPremission($uid)/*{{{*/
    {
        if (empty(AC::HOST_UID) || (AC::HOST_UID   ==  $uid))  return  TRUE;

        $array      =   array('uid' => AC::HOST_UID, 'fUid' => $uid, 'alarm' => TRUE);
        $isBlackMe  =   $this->followModel->isBlackMe($array);
        if (empty($isBlackMe))  return  TRUE;

        return  FALSE;
    }/*}}}*/
    
    /**
     * 获取日记的列表
     * @param unknown $uid
     * @param unknown $bodyId
     * @param string $check_uid
     * @return boolean|Ambigous
     */
    private function getDiaryDetailListInfo ($uid, $bodyId) {
        $listInfo   =   $this->diaryListModel->getDiaryInfoByBodyId($bodyId, $uid);
        if (empty($listInfo) || $listInfo['status'] != 0) {
            AC::$errorNo    =   'DC004';
            return  FALSE;
        }
        
        // 私密日记
        if ($listInfo['secret'] && AC::HOST_UID  !=  $listInfo['uid']) {
            AC::$errorNo  =   'DC008';
            return  FALSE;
        }
        
        // 转发的分享结构
        $structData = array();
        if($listInfo['extras']){
            $structData = $this->diaryListModel->structData($listInfo);
            if (!empty($structData) && $structData['url_type'] != 'article') {
                $listInfo['viewTimes']      =    strval($structData['viewTimes']);
                unset($structData['viewTimes']);
            }
        }
        
        $listInfo['url_struct']    =    array();
        if (!empty($structData)){
            $listInfo['url_struct'][] = $structData;
            $listInfo['attachmentList'] = array();
        }
        
        $geo = (Object) array();
        if ($listInfo['geo']['name'] && $listInfo['geo']['citycode']) {
            $geo = $listInfo['geo'];
        }
        $listInfo['geo'] = $geo;
        
        $listInfo['topic'] = $this->diaryListModel->getDiaryTopic($listInfo['topics']);
        //版本控制
        $product_version=    AC::$appInfoList[1];
        $os             =    strtolower(AC::$appInfoList[2]);
        $version = array(
            'android'          =>  '5.50',
            'ios'              =>  '5.5.0',
        );
        $check = version_compare($product_version, $version[$os],  '<=');
        if(!$check && isset($listInfo['url_struct'][0]['url_type']) && $listInfo['url_struct'][0]['url_type'] == 'article'){
            // 字符串截取（点滴列表中的内容被截取）
            $articleSummary = $listInfo['url_struct'][0]['url_content'];
            $contentTmp = UK::getstr($articleSummary, 500, '...');
            //如果点滴的内容和文章的摘要一样则不再显示
            if($listInfo['abbreviation'] == $contentTmp || $listInfo['abbreviation'] == '分享文章'){
                $listInfo['abbreviation']  = '';
            }
            $listInfo['title'] = '';
        }
        if($check && isset($listInfo['url_struct'][0]['url_type']) && $listInfo['url_struct'][0]['url_type'] == 'web') {
            if(strlen($listInfo['url_struct'][0]['url_title']) > 34){
                $listInfo['url_struct'][0]['url_title'] = UK::getstr($listInfo['url_struct'][0]['url_title'], 34, '...');
            }
            $listInfo['url_struct'][0]['url_content'] = UK::getstr($listInfo['url_struct'][0]['url_content'], 40);
        }

        // 精选判断
        $listInfo['essence'] = $this->diaryListModel->checkIsHotDiaryOfDetail($bodyId);
        //置顶
        $topic = json_decode($listInfo['topics'], true);
        $listInfo['display'] = $this->diaryListModel->checkIsTopDiaryOfDetail($topic['gid'], $bodyId);
        
        // 查看数
        $CWservice = new CountWeightService('diary', $bodyId);
        $numInfo = $CWservice->getCountWeight();
        $listInfo['viewTimes'] += $numInfo['n1'];
        $listInfo['repostTimes'] += $numInfo['n2'];

        $listInfo['abbreviation']   =   Emotion::emotionToCharacter($listInfo['abbreviation']);
        
        $listInfo['diary_type'] = ($listInfo['time'] >= AC::$diaryCommentCf['transfer_time']) ? 'topic_diary' : 'diary';
        unset($listInfo['extras']);
        unset($listInfo['topics']);
        return $listInfo;
    }

    /**
     * 获取bodyinfo
     * @return boolean|Ambigous <boolean, multitype:, unknown>
     */
    private function getDiaryDetailBodyInfo ($uid, $bodyId,$listInfo) {
        $bodyInfo   =   $this->diaryBodyModel->getDiaryBody($uid, $bodyId);
        if (!empty(AC::$errorNo)) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 返回字体信息
        $bodyInfo['font'] = $bodyInfo['place'] ? strval($bodyInfo['place']) : '0';
        
        // 返回信纸地址
        if (isset($bodyInfo['paper_url'])) {
            $bodyInfo['paper_url'] = $this->generatePaperUrl($bodyInfo['paper_url']);
        }

        //投票
		if($bodyInfo['vote']){
			$bodyInfo['vote']= $this->voteModel->getVoteInfo($bodyId, $uid,$bodyInfo['vote'], AC::HOST_UID);
		}
        // 表情对应的列表
        $emotion_ids_mebuy = array();
        if ($bodyInfo['extend']){
            $extend_arr = json_decode($bodyInfo['extend'], TRUE);
            $emotion_ids_mebuy = $extend_arr['shop_ids_mebuy'];
        }
        if (empty($emotion_ids_mebuy) && $bodyInfo['saveTime'] < Emotion::$filter_emotion_update_time){
            $emotion_ids_mebuy = Emotion::$default_emotion_ids;
        }
        if (isset($extend_arr['vip']['cardbg'])){
            $bodyInfo['vip']['cardbg'] = $this->generateVipCardUrl($extend_arr['vip']['cardbg']);
        }else{
            $bodyInfo['vip']['cardbg'] = '';
        }
        if (isset($extend_arr['source'])){
            $bodyInfo['source'] = $extend_arr['source'];
        }else{
            $bodyInfo['source'] = '';
        }

		if (isset($extend_arr['original'])){
			$bodyInfo['original'] = $extend_arr['original'];
		}else{
			$bodyInfo['original'] = '';
		}
		//链接
		$bodyInfo['linkList']  = Emotion::linkToList($bodyInfo['content'],$listInfo['linkList'],'LINK');
		$bodyInfo['content']   = Emotion::linkToMark($bodyInfo['content'],$listInfo['linkList'],'LINK');
		//声音
		$bodyInfo['voiceList']  = Emotion::linkToList($bodyInfo['content'],$listInfo['voiceList'],'VOICE');
		$bodyInfo['content']   = Emotion::linkToMark($bodyInfo['content'],$listInfo['voiceList'],'VOICE');
		//视频
		$bodyInfo['videoList']  = Emotion::linkToList($bodyInfo['content'],$listInfo['videoList'],'VIDEO');
		$bodyInfo['content']   = Emotion::linkToMark($bodyInfo['content'],$listInfo['videoList'],'VIDEO');

        $bodyInfo['imageList'] = Emotion::emotionToImgList($bodyInfo['content'], $emotion_ids_mebuy,$listInfo['attachmentList']);
//        $bodyInfo['content']   = UK::tipsUpgrade($attachment['voiceList'], $bodyInfo['content'], 'voice');
        $bodyInfo['content']   = Emotion::emotionToMark($bodyInfo['content'], $emotion_ids_mebuy,$listInfo['attachmentList']);
        $bodyInfo['in_review'] = isset($bodyInfo['inReview']) ? $bodyInfo['inReview'] : 0;


        unset($bodyInfo['extend']);
        return $bodyInfo;
    }
    
    /**
     * 获取附件
     * @param unknown $attachmentPath
     * @param unknown $uid
     * @param unknown $bodyId
     * @return Ambigous <multitype:, boolean, Ambigous>
     */
    private function getDiaryDetailAttachment ($attachmentPath, $uid, $bodyId) {
        $attachmentList =   array(
            'attachmentList'    =>  (Object) array(),
            'voiceList'         =>  (Object) array()
        );
        
        if (!empty($attachmentPath)) {
            $attachmentList =   $this->diaryAttachmentModel->getDiaryAllAttachment(array('uid' => $uid, 'bodyId' => $bodyId));
            // 图片附件
            if (!empty($attachmentList['attachmentList'])) {
                // 限制附件显示数量
                $attachmentList['attachmentList'] = arra_slice($attachmentList['attachmentList'], 0, AC::$topicDiaryAttachmentLimit );
            }
            // 语音附件
            if (!empty($attachmentList['voiceList'])) {
                $attachmentList['voiceList'] = $attachmentList['voiceList'];
            }
        }
        return $attachmentList;
    }
    
    /**
     * 获取日记作者
     * @param unknown $uid
     * @return unknown
     */
    private function getDiaryDetailAuthor ($uid, $check_follow = TRUE) {
        if ($check_follow) {
            $user	= $this->autoUidModel->getUserInfo($uid,'',AC::HOST_UID);
        }else{
            $user	= $this->autoUidModel->getUserInfo($uid);
        }
        $user   = $this->autoUidModel->checkIsMe($user);
        // 获取备注名
        $user['nickname']  = $this->autoUidModel->getRemarkName($user);
        return $user;
    }
    
    /**
     * followinfo
     * @param unknown $uid
     * @param string $check
     * @return multitype:StdClass
     */
    private function getDiaryDetailFollowInfo ($uid, $host_uid) {
        $followInfo = array(
            'followMe'  =>  (Object) array(),
            'meFollow'  =>  (Object) array()
        );
        // 判断跟用户关系
        if ((AC::HOST_UID !== $uid) && $host_uid ){
            $followInfo   =   $this->followModel->getFollowInfo(array('uid' => AC::HOST_UID, 'fUid' => $uid));
        }
        
        return $followInfo;
    }
    
    /**
     * 获取评论
     * @param unknown $uid
     * @param unknown $bodyId
     * @return Ambigous <boolean, unknown, multitype:>
     */
    private function getDiaryDetailCommentInfo ($uid, $bodyId) {
        $commentInfo = $this->commentModel->getCommentTop(array('uid' => $uid, 'bodyId' => $bodyId, 'type' => AC::FEED_DIARY));
        if (empty($commentInfo)){
            return array();
        }
        
        foreach ($commentInfo as &$comment){
            $userInfo = $this->autoUidModel->getUserInfo($comment['cUid']);
            $comment['avatar']  =  $userInfo['avatar'];
            $comment['user']    =  $this->autoUidModel->checkIsMe($userInfo);
            if ($comment['replyList'] && count($comment) > 0)
            {
                foreach ($comment['replyList'] as &$reply)
                {
                    $replyCuser = $this->autoUidModel->getUserInfo($reply['cUid']);
                    $replyRuser = $this->autoUidModel->getUserInfo($reply['rUid']);
                    $reply['cNickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$reply['cUid'],'nickname'=>$replyCuser['nickname']));
                    $reply['rNickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$reply['rUid'],'nickname'=>$replyRuser['nickname']));
                }
            }
            $comment['user']['nickname']  =    $this->autoUidModel->getRemarkName($comment['user']);
            $comment['cNickname'] = $comment['user']['nickname'];
        }
        return $commentInfo;
    }
    
    private function getDiaryCommentInfo ($uid, $bodyId) {
        $commentInfo = $this->commentModel->getCommentTop(array('uid' => $uid, 'bodyId' => $bodyId, 'type' => AC::FEED_DIARY));
        if (empty($commentInfo)){
            return array();
        }
        
        $result = $tmp = array();
        foreach ($commentInfo as $value) {
            $tmp = $this->commentModel->assembleOldDataOfComment($value);
            $result[] = $tmp;
        }
        return $result;
    }

    private function addFollowTopic($param){
        $param['uid'] = isset($param['uid']) ? intval($param['uid']) : 0;
        $param['topic_id'] = isset($param['topic_id']) ? intval($param['topic_id']) : 0;
        if ($param['uid']<1 || $param['topic_id']<AC::$diaryTopicCf['start_id']){
            AC::$errorNo    =   'DTC001';//参数错误
            return false;
        }
        $uid = $param['uid'];
        $topic_id = $param['topic_id'];
        $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($topic_id);
        $this->checkDiaryTopicIsValid($diaryTopic);
        if (AC::$errorNo) {
            UK::varDump(AC::$errorNo, __METHOD__);
            return FALSE;
        }
        //超过关注话题限制
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        if (count($gids)>=AC::FOLLOW_TOPIC_UPPER_LIMIT){
            AC::$errorNo    =   'DTC020';//超过关注话题限制
            return false;
        }
        if (in_array($topic_id, $gids)){
            AC::$errorNo    =   'DTC021';//已关注该话题
            return false;
        }
        $new = [
            'gid' => $topic_id, 'uid' => $uid
        ];
        $result = $this->groupMembersModel->addMembers($new);
        if ($result){
            $result = $this->diaryListCacheModel->addUserFollowTopic($uid, $topic_id);
            $result && $result = $this->groupInfoModel->addMemberNum([ 'gid'=>$topic_id ]);
        }
        return $result ? true : false;
    }

    private function removeFollowTopic($param){
        $param['uid'] = isset($param['uid']) ? intval($param['uid']) : 0;
        $param['topic_id'] = isset($param['topic_id']) ? intval($param['topic_id']) : 0;
        if ($param['uid']<1 || $param['topic_id']<AC::$diaryTopicCf['start_id']){
            AC::$errorNo    =   'DTC001';//参数错误
            return false;
        }
        $uid = $param['uid'];
        $topic_id = $param['topic_id'];
        //超过关注话题限制
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        if (!in_array($topic_id, $gids)){
            AC::$errorNo    =   'DTC022';//未关注该话题
            return false;
        }
        $new = [
            'gid' => $topic_id, 'uid' => $uid, 'status' => 1
        ];
        $result = $this->groupMembersModel->setGroupMember($new);
        if ($result){
            $result = $this->diaryListCacheModel->rmUserFollowTopic($uid);
            $this->groupInfoModel->delMemberNum([ 'gid'=>$topic_id ]);
        }
        return $result ? true : false;
    }

    private function getFollowTopics($param){
        $param['uid'] = isset($param['uid']) ? intval($param['uid']) : 0;
        if ($param['uid']<1){
            AC::$errorNo    =   'DTC001';//参数错误
            return false;
        }
        $uid = $param['uid'];
        //超过关注话题限制
        $gids = $this->groupMembersModel->getUserFollowTopics($uid);
        $diaryTopics = [];
        foreach ($gids as $gid){
            if($gid < 10000){
                continue;
            }
            $diaryTopic = $this->groupInfoModel->getDiaryTopicInfo($gid);
            $this->checkDiaryTopicIsValid($diaryTopic);
            if (AC::$errorNo){
                $this->removeFollowTopic([ 'uid'=>$uid, 'topic_id'=>$gid ]);
                AC::$errorNo = null;
                continue;
            }
            $diaryTopics[] = $diaryTopic;
        }
        $topics = $this->groupInfoModel->loopGroupList($diaryTopics, 0);
        $this->topicsCheckMeFollow($topics, $gids);
        $result = array('topics' => $topics, 'count' => count($topics));
        return $result;
    }

    private function topicsCheckMeFollow(&$topics, $follow_gids){
        if (empty($topics) || empty($follow_gids))return;
        foreach ($topics as &$topic){
            $topic['me_follow'] = in_array( $topic['id'], $follow_gids );
        }
    }

    private function diaryAddTop($param){
        $bodyId = isset($param['bodyId']) ? trim($param['bodyId']) : '';
        $level = isset($param['level']) ? trim($param['level']) : AC::SERVER_TIME;
        $uid = AC::HOST_UID;
        if ($bodyId<1 || $uid<1){
            AC::$errorNo = 'VIP001';//参数错误
            return false;
        }
        $listBody = $this->diaryListModel->getDiaryInfoByBodyId($bodyId);
        if (empty($listBody)){
            AC::$errorNo = 'LC004';
            return false;
        }
        if ($listBody['secret']){
            AC::$errorNo = 'DC008';
            AC::$errorMsg = '私密点滴不能置顶哦';
            return false;
        }
        $vip_info = $this->autoUidModel->getUserVipInfo($uid);
        if (empty($vip_info)){
            AC::$errorNo    =   'VIP002';//还不是会员
            return  FALSE;
        }
        $set = [
            'diary_top'=>strval($bodyId)
        ];
        $result = $this->userSettingModel->saveSetting($uid, $set);
        return $result ? true : false;
    }

    private function diaryRemoveTop($param){
        $bodyId = isset($param['bodyId']) ? trim($param['bodyId']) : '';
        $uid = AC::HOST_UID;
        if ($bodyId<1 || $uid<1){
            AC::$errorNo = 'VIP001';//参数错误
            return false;
        }
        $userSettingModel = new UserSettingModel();
        $set = [
            'diary_top'=>''
        ];
        $result = $this->userSettingModel->saveSetting($uid, $set);
        return $result ? true : false;
    }

    private function getDiaryTopBodyids($uid){
        $toplist = [];
        $info = $this->userSettingModel->getSettingInfo($uid);
        $info && $top = $this->userSettingModel->getDiaryTopFromSetting($info);
        $top && $toplist[] = $top;
        return $toplist;
    }
    
    private function checkAction($action){
    
        if (in_array($action, $this->actions) && method_exists($this, $action))  return  TRUE;
        AC::$errorNo    =   'SA004';
        return  ' Error : call action is not exists in DiaryController! ';
    }

    /**
    *   订阅号打赏
    */
    public function subscriptionReward($param){
        if(empty($param['bodyId']) || $param['bodyId'] < 1000){
            AC::$errorNo = 'DTC001';
            return false;
        }
        if(AC::$subscriptionVersion){
            if(empty($param['uid'])){
                AC::$errorNo = 'DTC001';
                return false;
            }
        }

        //$diaryInfo = $this->diaryListModel->getDiaryInfoByBodyId($param['bodyId']);
        $articleService = new ArticleService();
        $diaryInfo = $articleService->getArticleInfo($param['bodyId'], $param['uid']);
        if(!$diaryInfo){
            AC::$errorNo = 'DC004';
            return false;
        }

        $reward_status = 1;  //开启
        $os = UK::checkOS(AC::$appInfoList[2]);
        $os == 2 && $reward_status = 0;   //ios关闭
        AC::HOST_UID == $diaryInfo['uid'] && $reward_status = 0;   //进入自己的文章也关闭按钮
        $userInfo = $this->autoUidModel->getUserInfo($param['uid']);
        if(!$userInfo['verified']){
            $reward_status = 0;
        }
        if(!AC::$subscriptionVersion){
            $reward_status = 0;
        }

        //获取该文章的打赏列表
        if(AC::ENV_TEST){
            $uidArr = $this->diaryListModel->getRewardListTest($param['uid'], $param['bodyId']);
            $main_url = 'http://v2subscribego.coin.ffrj.net/Reward/rewardHome?signature=1&action=payment&bodyId='.$param['bodyId'].'&auid='.$param['uid'];
            $list_url = 'http://v2subscribego.coin.ffrj.net/Reward/rewardHome?signature=1&action=dashangFd&bodyId='.$param['bodyId'].'&auid='.$param['uid'];
        }else{
            $uidArr = $this->diaryListModel->getRewardList($param['uid'], $param['bodyId']);
            $main_url = 'http://v2subscribego.coin.fenfenriji.com/Reward/rewardHome?signature=1&action=payment&bodyId='.$param['bodyId'].'&auid='.$param['uid'];
            $list_url = 'http://v2subscribego.coin.fenfenriji.com/Reward/rewardHome?signature=1&action=dashangFd&bodyId='.$param['bodyId'].'&auid='.$param['uid'];
        }
        
        $userInfo = array();
        if($uidArr){
            foreach ($uidArr as $key => $val) {
                $user = $this->autoUidModel->getUserInfo($val);
                if(!$user){
                    AC::$errorNo = null;
                    continue;
                }
                $userInfo[] = [
                    'uid' => $val,
                    'user' => $user
                ];
            }
        }
        
        $data = array(
            'main_url' => $main_url,
            'list_url' => $list_url,
            'users'    => $userInfo,
            'reward_num'    => count($userInfo),
            'reward_status' => $reward_status
        );
        return $data;
    }

    /**
     * 打赏列表
     */
    public function getRewardList($param)
    {
        if(empty($param['bodyId']) || $param['bodyId'] < 1000 || empty($param['uid'])){
            AC::$errorNo = 'DTC001';
            return false;
        }
        //$diaryInfo = $this->diaryListModel->getDiaryInfoByBodyId($param['bodyId']);
        $articleService = new ArticleService();
        $diaryInfo = $articleService->getArticleInfo($param['bodyId'], $param['uid']);
        if(!$diaryInfo){
            AC::$errorNo = 'DC004';
            return false;
        }
        //获取该文章的打赏列表
        $uidArr = [];
        if(AC::ENV_TEST){
            $uidArr = $this->diaryListModel->getRewardListTest($param['uid'], $param['bodyId']);
        }else{
            $uidArr = $this->diaryListModel->getRewardList($param['uid'], $param['bodyId']);
        }
        $userInfo = array();
        if($uidArr){
            foreach ($uidArr as $key => $val) {
                $user = $this->autoUidModel->getUserInfo($val);
                if(!$user){
                    AC::$errorNo = null;
                    continue;
                }
                $userInfo[] = [
                    'uid' => $val,
                    'user' => $user
                ];
            }
        }
        
        $data = array(
            'users'     => $userInfo,
            'user_num'  => count($userInfo)
        );
        return $data;
    }
}

